logoalt Hacker News

AnotherGoodNametoday at 1:44 AM18 repliesview on HN

Add this to .claude/settings.json:

  {                                                                                                                                                              
    "sandbox": {                                                                                                                                               
      "enabled": true,
      "filesystem": {
        "allowRead": ["."],
        "denyRead": ["~/"],
        "allowWrite": ["."],
        "denyWrite": ["/"]
      }                                                                                                                                                          
    }
  }

You can change the read part if you're ok with it reading outside. This feature was only added 10 days ago fwiw but it's great and pretty much this.

Replies

mazierestoday at 3:40 AM

I've seen claude get confused about what directory it's in. And of course I've seen claude run rm -rf *. Fortunately not both at the same time for me, but not hard to imagine. The claude sandbox is a good idea, but to be effective it would need to be implemented at a very low level and enforced on all programs that claude launches. Also, claude itself is an enormous program that is mostly developed by AI. So to have a small <3000-line human-implemented program as another layer of defense offers meaningful additional protection.

show 6 replies
harikbtoday at 2:04 AM

I think the point would be that - some random upcoming revision of claude-code could remove or simply change the config name just as silently as it was introduced.

People might genuinely want some other software to do the sandboxing. Something other than the fox.

mazierestoday at 5:10 AM

Also, a lot of people use multiple harnesses. I'm often switching between claude, codex, and opencode. It's kind of nice to have the sandbox policy independent of the actual AI assistant you are running.

Abishek_Muthiantoday at 7:42 AM

It's common practice to ask the agent to refer to another project, in that case I guess the read should point to the root folder of the projects.

Also, any details on how is this enforced? because I notice that the claude in Windows don't respect plan mode always; It has edited files in plan mode; I never faced that issue in Linux though.

cozzydtoday at 2:06 AM

Is this a real sandbox or just a pretty please?

show 3 replies
8cvor6j844qw_d6today at 2:11 AM

Interesting, thanks. I use remote ephemeral dev containers with isolated envs, so filesystem damage isn't really a concern as long as the PR looks good in review. Nice extra guardrail though, will add it to the project-level settings.

show 1 reply
cardernetoday at 6:33 AM

I’m surprised it works for you with such a simple config? I’m the one that added the allowRead option to Claude’s underlying sandbox [0] and had quite a job getting my toolchains and skills to work with it [1].

[0] Fun to see the confusing docs I wrote show up more or less verbatim on Claude’s docs.

[1] My config is here, may be useful to someone: https://github.com/carderne/pi-sandbox/blob/main/sandbox.jso...

gmerctoday at 6:27 AM

It’s cute because Claude has discretion to disable its own sandbox and does it

show 1 reply
yu3zhou4today at 6:16 AM

So in some sense we start recreating an operating system, or at least the userspace, within the Claude code. There was some name for this pattern but I can’t recall

show 3 replies
globular-toasttoday at 7:36 AM

And you'd trust that given CC is a vibe-coded mess?

nurettintoday at 3:33 AM

It will just do

    ssh you@localhost "rm -rf ~"
show 1 reply
tasntoday at 4:09 AM

I use bbwrap to sandbox Claude. Works very well and gives me a lot of control and certainty around the sandbox.

andaitoday at 4:31 AM

Does this also apply to the commands or programs that it runs?

e.g. if it writes a script or program with a bug which affects other files, will this prevent it from deleting or overwriting them?

What about if the user runs a program the agent wrote?

weinzierltoday at 6:52 AM

Is this a hard sandbox (enforced outside the LLM)?

mycalltoday at 2:03 AM

I noticed codex has a sandbox, wondering if it has a comparable config section.

croestoday at 6:49 AM

Is that hard setting or does it depend on claude’s interpretation?

The latter could end like this https://news.ycombinator.com/item?id=47357042

whattoday at 4:12 AM

lol if you think Claude is smart enough to block sneaky path strings based on your config.

dealfinder994today at 7:49 AM

[dead]