Skip to content
,

Claude Code Sandbox: Setup, Modes, Network Rules and Fixes (2026)

7–10 minutes
Woman in a home lab with a PC tower holding a tablet with a SANDBOX card, hook safe AI shell commands

The Claude Code sandbox puts an operating-system boundary around the shell commands Claude runs. You decide which folders those commands can write to and which network domains they can reach, and the limits also apply to every process those commands start.

Turn it on with one command, /sandbox, and you can let Claude run builds and tests with far fewer permission prompts while keeping your SSH keys, home folder and the wider internet out of reach.

This guide covers what the sandbox restricts, setup on macOS, Linux and WSL2, the two sandbox modes, how to confirm it works, filesystem and network settings with examples, excludedCommands, strict mode, limitations and fixes for tools that break (Docker, jest, gh). It follows Anthropic’s official Claude Code documentation as of December 2026.

TL;DR

  • Turn on: run /sandbox, or set "sandbox": {"enabled": true} in settings. It is off by default.
  • Platforms: macOS (Seatbelt), Linux and WSL2 (bubblewrap + socat). Native Windows runs unsandboxed.
  • Writes: only the project, a temp folder and added directories.
  • Network: through a local proxy; allowed domains start empty.
  • Modes: auto-allow (no prompts for sandboxed commands) or regular permissions.
  • Covers shell only: file tools, MCP servers and hooks run outside it.

What the Sandbox Restricts

While the sandbox is on, Bash, PowerShell and Monitor commands start inside its boundary, and so do their child processes. It is built on Anthropic’s open source @anthropic-ai/sandbox-runtime package.

Access Default Change it with
Writes Working directory, a per-user temp folder and directories you added filesystem.allowWrite, denyWrite
Reads Most of the machine, including ~/.ssh and ~/.aws/credentials filesystem.denyRead, credentials
Network No direct route; a local proxy checks each host. Allowed domains start empty network.allowedDomains, deniedDomains
Environment Inherited from Claude Code, secrets included credentials, CLAUDE_CODE_SUBPROCESS_ENV_SCRUB

Note that reads are wide open by default. If you care about secrets, add denyRead rules (examples below).

What runs outside the sandbox

  • Built-in tools such as Read, Edit, Write, WebFetch and WebSearch. They follow permission rules in your settings instead.
  • Command hooks, local MCP servers, plugin monitors, LSP servers and your status line command.
  • Commands you type yourself at the ! shell prompt (in most sessions), commands in excludedCommands and approved unsandboxed retries.

To put everything behind one boundary, run Claude Code itself in a container, VM or the sandbox runtime. Our hooks guide and MCP setup guide cover those parts.

Turn On the Sandbox

  1. macOS needs nothing extra. On Linux or WSL2, install the dependencies first (next section).
  2. Start Claude Code in your project and run /sandbox.
  3. The panel has Mode, Overrides and Config tabs. On Linux a Dependencies tab appears when something is missing.
  4. On the Mode tab, choose auto-allow or regular permissions.
  5. On Overrides, decide whether failed commands may fall back to running unsandboxed (allowUnsandboxedCommands).
  6. Ask Claude to run your build or tests. The first time a command needs a new domain, you are asked to approve it.

Your choice is saved to .claude/settings.local.json for the current project. To sandbox every project, add this to ~/.claude/settings.json:

{
  "sandbox": {
    "enabled": true
  }
}

For one session only, with no unsandboxed retries:

claude --settings '{"sandbox": {"enabled": true, "allowUnsandboxedCommands": false}}'

Warning: if the platform is unsupported or the dependency check fails, Claude Code runs commands unsandboxed by default. Set sandbox.failIfUnavailable to true to make it exit instead.

Linux and WSL2 Setup

  1. Install the packages. Ubuntu/Debian: sudo apt-get install bubblewrap socat. Fedora: sudo dnf install bubblewrap socat.
  2. Optional: install the seccomp filter for Unix socket blocking with npm install -g @anthropic-ai/sandbox-runtime.
  3. Restart Claude Code, because the dependency check runs at startup, then run /sandbox.
  4. On WSL, run wsl -l -v in PowerShell. WSL1 is not supported; upgrade to WSL2.

Ripgrep is bundled with the native binary. If Ubuntu’s AppArmor restriction blocks bubblewrap, the docs give an AppArmor profile for /usr/bin/bwrap with userns permission; add it, run sudo systemctl reload apparmor and restart Claude Code. Setting up WSL? See our Claude Code install guide.

Auto-Allow vs Regular Permissions Mode

Mode Sandboxed commands Best for
Auto-allow Run with no prompt Fast work with a safety boundary
Regular permissions Still prompt as usual Maximum control

Both modes enforce the same filesystem and network limits. Even in auto-allow mode:

  • Bash deny rules still block matching commands.
  • rm or rmdir on critical paths still goes through the normal permission flow.
  • Content-scoped ask rules such as Bash(git push *) still prompt.
  • Commands like FOO=bar npm test, make CC=clang or eval "ls" go through normal permissions. Add a matching allow rule such as Bash(make *) to stop repeat prompts.
  • Monitor commands are not auto-approved.

In Plan Mode, auto-allow does not widen approvals; see our Plan Mode guide.

Confirm Commands Run Sandboxed

Ask Claude (not the ! prompt) to run these:

Command Expected result
touch ~/sandbox-probe Operation not permitted on macOS, Read-only file system on Linux/WSL2
curl --noproxy '*' https://example.com Could not resolve host

If Claude offers to retry outside the sandbox, decline. If touch succeeds, delete the probe file and recheck /sandbox.

Filesystem Settings

Give a tool write access to one extra place instead of removing it from the sandbox:

{
  "sandbox": {
    "enabled": true,
    "filesystem": {
      "allowWrite": ["~/.kube", "/tmp/build"]
    }
  }
}

Block reads of your whole home folder but keep the project readable (put this in the project’s .claude/settings.json, where . means the project root):

{
  "sandbox": {
    "enabled": true,
    "filesystem": {
      "denyRead": ["~/"],
      "allowRead": ["."]
    }
  }
}
  • When read rules overlap, the narrower path wins. "allowRead": ["~/"] with "denyRead": ["~/**/.env"] blocks every .env file.
  • Sandbox paths use normal conventions: /tmp/build is absolute, ~/.kube is in your home. This differs from Read/Edit permission rules.
  • On Linux and WSL2, a path that does not exist yet has no effect, so create it first.
  • Arrays from different settings files are merged, and edits apply to the next command without a restart.

Network Settings

Sandboxed commands have no direct network route. A proxy on your machine checks each hostname. Tools that respect HTTP_PROXY/HTTPS_PROXY, such as curl, npm and git over HTTPS, work once the host is allowed. Plain ssh, most database drivers and anything that is not TCP (UDP, QUIC, ping) cannot connect.

{
  "sandbox": {
    "enabled": true,
    "network": {
      "allowedDomains": ["registry.npmjs.org", "github.com", "pypi.org"]
    }
  }
}
  • Choosing Yes at a domain prompt allows it for the session; Yes, and don’t ask again saves a WebFetch(domain:...) allow rule.
  • strictAllowlist: true (user, managed or --settings) denies other hosts instead of prompting.
  • Behind a corporate proxy, set HTTPS_PROXY, HTTP_PROXY and NO_PROXY in the settings env block.

Be careful with broad domains like github.com: the proxy does not inspect TLS by default, so wide allowlists can create exfiltration paths.

Run a Tool Outside the Sandbox

For tools that cannot work sandboxed, such as Docker:

{
  "sandbox": {
    "enabled": true,
    "excludedCommands": ["docker compose *"]
  }
}
  • End patterns with *; docker alone matches only a bare docker.
  • Every command in a chained call must match, so npm ci && docker compose build stays sandboxed unless npm ci is also covered.
  • A script that calls docker internally does not match.
  • Excluded commands run with your full access and go through normal permissions, prompting as “Bash command (unsandboxed)”.

Strict Mode and the Retry Escape Hatch

When a command fails in the sandbox, Claude may retry it with dangerouslyDisableSandbox. Who approves depends on your mode: a prompt in manual and acceptEdits modes, a classifier in auto mode, automatic in bypassPermissions, and denied in dontAsk. Add an ask rule for Bash(dangerouslyDisableSandbox:true) to always be asked.

To turn retries off completely, set "allowUnsandboxedCommands": false. A false in your user settings holds even if a project sets true. If it is set in managed settings or --settings, the sandbox becomes admin-required and project files cannot loosen it.

Limitations

  • It is not a complete isolation boundary. TLS is not inspected by default, so domain fronting is possible through broad allowed domains.
  • Allowing Unix sockets like /var/run/docker.sock effectively grants host access.
  • Write access to folders in $PATH or to .bashrc/.zshrc can lead to code execution outside the sandbox.
  • enableWeakerNestedSandbox (for Docker without privileged namespaces) considerably weakens security.
  • allowAppleEvents on macOS removes code-execution isolation.
  • Subagents share the parent’s sandbox; computer use runs on your real desktop.

Effective sandboxing needs both filesystem and network isolation. Running Claude unattended in auto mode? Read our Claude Code auto mode guide too.

Troubleshooting

Host not allowed errors

Approve the host when prompted or add it to allowedDomains. With allowManagedDomainsOnly, ask your admin.

jest hangs or fails

watchman is incompatible. Run jest --no-watchman.

docker commands fail

Docker is incompatible with the sandbox. Add a narrow excludedCommands pattern such as docker compose *.

gh, gcloud or terraform fail TLS on macOS

Go-based CLIs can fail under Seatbelt. Add patterns like gh * to excludedCommands.

open or browser login fails with -600 on macOS

Apple Events are blocked. Set allowAppleEvents: true in user settings (it removes isolation), or exclude open *.

git over SSH or a database client fails

These ignore the proxy variables. Use HTTPS for git, or exclude the specific command.

Only a Dependencies tab shows

Install bubblewrap and socat, fix AppArmor if reported, and restart Claude Code.

FAQ

Does the Claude Code sandbox work on Windows?

Not natively. Run Claude Code inside WSL2 to use it.

Is the sandbox on by default?

No. Run /sandbox or set sandbox.enabled to true.

Does the sandbox stop Claude editing files outside my project?

It limits shell commands. The Edit and Write tools follow permission rules, so use deny rules for those.

Will the sandbox slow Claude Code down?

It usually saves time, because auto-allow mode removes most Bash permission prompts.

Can I use the sandbox with –dangerously-skip-permissions?

Yes, but in bypassPermissions mode unsandboxed retries run without a prompt, so set allowUnsandboxedCommands: false.

Can admins enforce the sandbox?

Yes. Managed settings can require it, lock domains with allowManagedDomainsOnly and stop projects widening the policy.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a home lab with a PC tower holding a tablet with a SANDBOX card, hook safe AI shell commands