Claude Code sandbox: what it blocks and what still runs outside it
The Claude Code sandbox is a boundary the operating system draws around the shell commands Claude runs. It's off by default, it covers Bash, PowerShell and Monitor commands and nothing else, and one command, /sandbox, switches it on.
Claude Code sandbox
- Checked
- 28 October 2026
- Default
- Off
- Turn it on
- /sandbox or sandbox.enabled
- Platforms
- macOS, Linux, WSL2
- Not covered
- File tools, hooks, local MCP servers
The short answer
The Claude Code sandbox restricts what shell commands can read, write and reach on the network, and the operating system enforces it. It's off by default. Turn it on with /sandbox, or set sandbox.enabled in a settings file. File tools, hooks, local MCP servers and commands you type yourself run outside it, so it narrows the risk and doesn't close it.
What the sandbox restricts by default
The sandbox is a boundary that the operating system enforces around the shell commands Claude runs on your machine, and around the processes those commands start. It covers Bash, PowerShell and Monitor commands. Anthropic builds it on the open source sandbox-runtime package, and the sandboxing page lists the defaults below.
| Access | Default | Change it with |
|---|---|---|
| Writes | The working directory, a per-user temp directory and directories you added. Protected paths stay write-denied. | sandbox.filesystem.allowWrite and denyWrite |
| Reads | Most of the machine, including credential files such as ~/.ssh and ~/.aws/credentials. | sandbox.filesystem.denyRead and sandbox.credentials |
| Network | No direct route out. Connections go through a proxy on your machine that checks each host against your allowed domains, which start empty. | sandbox.network.allowedDomains and deniedDomains |
| Environment variables | Inherited from Claude Code, including any secrets in its environment. | sandbox.credentials and CLAUDE_CODE_SUBPROCESS_ENV_SCRUB |
The read default surprises people. A sandboxed command can read your SSH keys unless you deny them, so the sandbox protects what you tell it to protect.
Turn it on and check that it holds
- Start a session and run
/sandbox. The panel has Mode, Overrides and Config tabs. On Linux and WSL2, install bubblewrap and socat first, or the panel shows only a Dependencies tab. - Pick a mode. Auto-allow runs sandboxed commands without a prompt, and regular permissions keeps the prompts even for sandboxed commands.
- Ask Claude to run
touch ~/sandbox-probe. Inside the sandbox it fails with Operation not permitted on macOS, or Read-only file system on Linux. Ask it to runcurl --noproxy '*' https://example.comand it should fail with Could not resolve host. - Decline any request to retry unsandboxed, and don't test by typing the commands yourself. What you type at the
!prompt usually runs outside the sandbox, so the test proves nothing. - Make it stick. Set
sandbox.enabledto true in~/.claude/settings.jsonfor every project, or start one session withclaude --settings '{"sandbox": {"enabled": true, "allowUnsandboxedCommands": false}}'.
Two modes and two ways out
The sandbox enforces the same file and network limits in both modes. The modes differ in who approves the command, and two settings let a command leave the sandbox altogether.
Auto-allow mode. A command that runs inside the sandbox is auto-approved with no prompt. A Bash deny rule that matches still blocks it, a content-scoped ask rule such as Bash(git push *) still prompts, and recognised rm commands on critical paths still go through the normal permission flow.
Regular permissions mode. Every command goes through the usual permission flow even when it runs sandboxed. It asks more often and gives you the most control.
The unsandboxed retry. When a command fails inside the sandbox, Claude can retry it with the dangerouslyDisableSandbox parameter. That's an escape hatch. In bypassPermissions mode the retry runs with no prompt, and in manual and acceptEdits modes you get one. Set allowUnsandboxedCommands to false and Claude Code ignores the parameter.
Excluded commands. Anything that matches sandbox.excludedCommands runs outside the sandbox, with your full access. A broad pattern such as docker * covers everything that tool can do, so write the narrowest pattern that works or grant the specific path with allowWrite instead.
What still runs outside the sandbox
- Built-in file and web tools. Read, Edit, Write, WebFetch and WebSearch follow permission rules, so a
denyReadentry doesn't stop the Read tool andallowedDomainsdoesn't limit WebFetch. - Hooks, local MCP servers and monitors. Command hooks, local MCP servers, plugin monitors, language servers and helpers such as your status line command run with your full access.
- Commands you type yourself. A command entered at the
!shell-mode prompt runs unsandboxed in most sessions. - Native Windows. Claude Code runs commands unsandboxed there, so use WSL2 or a container.
- Anything you widen. An
allowWritepath, a broad domain or an excluded command can undo a restriction on the other side.
Where the sandbox stops
- It filters by hostname. The proxy doesn't inspect TLS by default, so allowing a broad domain such as github.com can open a path for data to leave, and Anthropic names domain fronting as a possible route.
- Tools that ignore the proxy variables can't connect. Plain ssh and most database drivers fail even to an allowed host, and anything that isn't TCP, such as UDP, QUIC and ping, can't leave.
- An allowed Unix socket can be a way out. Allowing
/var/run/docker.sockeffectively gives a command the host. - Write access to the wrong place is escalation. Letting a command write to a directory on your PATH or to
.bashrcor.zshrclets it run code in a different context later. - Linux inside Docker is weaker. The
enableWeakerNestedSandboxoption makes it work without privileged namespaces and considerably weakens it. - On macOS,
allowAppleEventsremoves code-execution isolation. Sandboxed commands can then launch other applications unsandboxed.
Enforce it for a team, or put the whole process in a box
To require the sandbox for every developer, deliver the sandbox keys through managed settings, either as a file your MDM manages or as server-managed settings. Anthropic's example turns the sandbox on, makes Claude Code refuse to start if it can't run, and closes the unsandboxed retry.
% cat managed-settings.json
{
"sandbox": {
"enabled": true,
"failIfUnavailable": true,
"allowUnsandboxedCommands": false
}
}
A boolean set in managed settings overrides whatever a developer sets locally. Array keys such as allowRead merge across scopes, so a developer can append entries unless a lock covers the key. The same settings stop a repository's own files from taking commands out of the sandbox. On native Windows, failIfUnavailable makes Claude Code exit at startup, so deliver the file to macOS and Linux machines only or move Windows users into WSL2.
The Bash sandbox leaves file tools, hooks and MCP servers outside, so for unattended runs Anthropic points to a wider boundary. The sandbox runtime wraps the whole Claude Code process without Docker. Dev containers, custom containers and virtual machines isolate the full environment, and cloud sessions run in a VM Anthropic hosts. Anthropic says to run --dangerously-skip-permissions only inside a container, a VM or the sandbox runtime, as a non-root user on Linux and macOS, because Claude Code refuses to start with that flag as root.
Sandbox, permission rules and permission modes are three layers
People ask whether the sandbox replaces permissions. It doesn't. Anthropic's documentation treats them as complementary, and the table shows what each layer decides. The rules and modes have their own guide in Claude Code permissions.
| Layer | What it controls | What replaces the prompt |
|---|---|---|
| Permission rules | Which tools Claude can use, checked before any tool runs, for every tool | A deny, ask or allow decision |
/sandbox | What a Bash command can access once it runs | The sandbox boundary itself, in auto-allow mode |
| Auto mode | Whether each tool call runs | A classifier that reviews actions |
--dangerously-skip-permissions | Whether each tool call runs | Nothing, and protected-path checks are skipped too |
What we tested
We ran these commands on 28 October 2026 with Claude Code 2.1.274 on a Mac (Apple silicon, macOS 26.4), in a throwaway folder with an empty home directory. /sandbox is an interactive panel that needs a signed-in session, so we didn't run it, and we didn't send a prompt. What we could check without an account is whether Claude Code accepts the sandbox settings above and what the operating system's own sandbox does.
% claude --version
2.1.274 (Claude Code)
% claude doctor | grep -c "Invalid settings"
0
That second command ran in a folder whose .claude/settings.json held the three-key managed example, and it found no invalid settings. In a second folder we saved "enabled": "yes" and a plain string for allowedDomains. claude doctor, trimmed here to its Invalid settings section with the working folder replaced by a dot, rejected both.
% claude doctor
Invalid settings
- ./.claude/settings.json › sandbox.enabled: Expected boolean, but received undefined
Suggested fix: Use true or false without quotes. Example: "includeCoAuthoredBy": true
- ./.claude/settings.json › sandbox.network.allowedDomains: Expected array, but received undefined
% npm view @anthropic-ai/sandbox-runtime version time.modified license
version = '0.0.81'
time.modified = '2026-10-20T01:13:24.300Z'
license = 'Apache-2.0'
The npm record shows the open source runtime Anthropic names, at version 0.0.81 under Apache-2.0, last modified 20 October 2026. The next check isn't Claude Code. It runs the macOS Seatbelt primitive that Anthropic says Claude Code uses on Macs, with a profile we wrote ourselves, to show the two failure messages the docs list. The first command denies writes under one folder, the second writes elsewhere, and the third denies all network access.
% sandbox-exec -p "(version 1)(allow default)(deny file-write* (subpath \"$PWD/locked\"))" /usr/bin/touch locked/probe
touch: locked/probe: Operation not permitted
exit 1
% sandbox-exec -p "(version 1)(allow default)(deny file-write* (subpath \"$PWD/locked\"))" /usr/bin/touch open/probe
exit 0
% sandbox-exec -p '(version 1)(allow default)(deny network*)' /usr/bin/curl -sS -m 5 https://example.com -o /dev/null
curl: (6) Could not resolve host: example.com
exit 6
The kernel produced Operation not permitted for the write and Could not resolve host for the request, the same two messages Anthropic's table gives for a sandboxed touch and curl. That shows the mechanism. It doesn't show that Claude Code's own profile holds, which is what the check in step three above is for. Anthropic's documentation describes versions up to 2.1.302 and this machine runs 2.1.274, so a setting added since may not exist locally.
Where this has mattered, and where to read next
- A sandbox earns its place when something misbehaves. In October, Cohere said an open-weight model tried to upload a test file to a Beijing storage bucket and its sandbox stopped it. That was Cohere's sandbox, not Claude Code's, and parts of the account are disputed, so our brief separates what is confirmed.
- The brief on the AGENTS.md attack lists keeping approvals and sandboxes on among what should have been in place.
- The rules and modes around the sandbox are in Claude Code permissions, and everything else Anthropic ships is in Is Claude Code safe?
- How another tool draws its boundary is in Claude Code vs Cursor, and the plans are in Is Claude Code free?
- Our settings files study estimated that only 1.0% of public settings files turn the sandbox on, from 12,796 files read.
- For a team rollout, read Claude Code governance. The work sits under our production engineering, AI agent development and custom AI development practice.
Frequently asked questions
Is the Claude Code sandbox on by default?
No. Anthropic's documentation says the sandbox is off by default. Turn it on by running /sandbox in a session, or set sandbox.enabled to true in a settings file such as ~/.claude/settings.json.
Does the Claude Code sandbox work on Windows?
Not on native Windows, where Claude Code runs commands unsandboxed. It runs on macOS, Linux and WSL2. On a Windows machine, run Claude Code inside WSL2, a container or a virtual machine.
Should I run Claude Code in Docker or use the built-in sandbox?
They cover different things. The built-in sandbox restricts shell commands only, and file tools, MCP servers and hooks stay outside it. A container, a VM or the sandbox runtime puts the whole process inside the boundary, which Anthropic says to use for unattended runs with --dangerously-skip-permissions.
Can Claude turn the sandbox off by itself?
It can ask. If a command fails inside the sandbox, Claude may retry it with dangerouslyDisableSandbox. In manual and acceptEdits modes you get a prompt, and in bypassPermissions mode the retry runs without one. Setting allowUnsandboxedCommands to false makes Claude Code ignore it.
What can a sandboxed command still read?
Most of the machine by default, including credential files such as ~/.ssh and ~/.aws/credentials. Use sandbox.filesystem.denyRead, sandbox.credentials or permissions.blockReadsOutsideWorkingDirectories to narrow it.
Sources, checked 2026-10-28
8 sources
- The Claude Code sandbox is off by default, is turned on with /sandbox or sandbox.enabled, covers Bash, PowerShell and Monitor commands and their processes, and runs on macOS, Linux and WSL2 but not native Windows.Source: code.claude.com, checked 2026-10-28.
- Sandboxed commands can write to the working directory, a per-user temp directory and added directories, can read most of the machine including credential files, and reach the network only through a proxy with allowed domains that start empty.Source: code.claude.com, checked 2026-10-28.
- Built-in file and web tools, command hooks, local MCP servers, plugin monitors and commands typed at the ! prompt run outside the sandbox in most sessions.Source: code.claude.com, checked 2026-10-28.
- A command that fails in the sandbox can be retried unsandboxed with dangerouslyDisableSandbox, which runs without a prompt in bypassPermissions mode, and allowUnsandboxedCommands set to false turns the retry off.Source: code.claude.com, checked 2026-10-28.
- The sandbox does not inspect TLS by default, a broad allowed domain can create an exfiltration path, an allowed Unix socket such as docker.sock can grant host access, and enableWeakerNestedSandbox and allowAppleEvents weaken isolation.Source: code.claude.com, checked 2026-10-28.
- Managed settings with enabled, failIfUnavailable and allowUnsandboxedCommands false require the sandbox for every developer, and failIfUnavailable makes Claude Code exit at startup on native Windows.Source: code.claude.com, checked 2026-10-28.
- The sandboxed Bash tool isolates shell commands only, while the sandbox runtime, dev containers, VMs and cloud sessions put the whole Claude Code process inside a boundary, and --dangerously-skip-permissions belongs inside a container, a VM or the sandbox runtime.Source: code.claude.com, checked 2026-10-28.
- Claude Code builds its sandbox on the open source @anthropic-ai/sandbox-runtime package.Source: github.com, checked 2026-10-28.
Digiton Dynamics OÜ is registered in Tallinn, Estonia, and delivers from Lisbon.
Update log
- Published. Defaults and limits read from Anthropic's sandboxing and sandbox environments pages, commands run on Claude Code 2.1.274.
Each source above was opened on the date beside it. How facts get chosen and checked is written down in the editorial policy.
Talk to an engineer about your system
Book a free 25-minute scoping call. We tell you what we would build, what it takes to keep it running, and whether we are the right fit.
