Claude Code sandbox: what it covers and what it doesn’t
How the Claude Code sandbox works (/sandbox, Seatbelt, bubblewrap, network allowlist), what it protects, the gaps (file tools, MCP servers, hooks, env secrets), and settings to close them.
Updated
The Claude Code sandbox limits the commands Claude runs: they can write only inside your project and temp folders, and reach only the network domains you allow. Turn it on with /sandbox. It doesn’t cover Claude’s own file tools, MCP servers or hooks, it can read most of your machine unless you deny it, and commands inherit your environment variables, secrets included.
As of November 2026, from Anthropic’s sandboxing docs. Part of Keep coding agents safe.
How the sandbox works
The sandbox wraps “Bash, PowerShell, and Monitor commands and the processes they start” in an operating-system boundary: Seatbelt on macOS, bubblewrap on Linux and WSL2. Native Windows runs without it.
| Area | Inside the sandbox |
|---|---|
| Writing files | Only the project, your temp folder and folders you add. Protected paths like .git hooks stay blocked |
| Reading files | Most of the machine, including ~/.ssh and ~/.aws, unless you deny it |
| Network | Only through a local proxy, to domains you allow. The list starts empty |
| Environment | Everything Claude Code has, including secrets in env variables |
Because the operating system enforces it, an rm -rf ~ from a sandboxed command fails no matter how it’s written: no text match to slip past.
Turn it on
Run /sandbox in Claude Code and pick a mode. Or set it in ~/.claude/settings.json:
{
"sandbox": {
"enabled": true,
"allowUnsandboxedCommands": false
}
}
With auto-allow, sandboxed commands run without a prompt. Deny rules, ask rules and the check on deleting critical paths still apply.
What the sandbox doesn’t cover
This is the part most guides skip. From Anthropic’s docs:
- Claude’s own tools. Read, Edit, Write, WebFetch and WebSearch run outside it. “A
denyReadentry doesn’t stop the Read tool, andallowedDomainsdoesn’t limit WebFetch.” Use permission rules for those. - MCP servers, hooks, the status line and
apiKeyHelperrun outside it. - Commands you type yourself with
!run outside it. - Your secrets. Commands inherit Claude Code’s environment, so a token in an env variable is readable inside the box.
- Reads. By default a sandboxed command can read
~/.sshand cloud credentials. Writes are limited; reads aren’t. - The retry. When a command fails in the sandbox, Claude can retry it outside with
dangerouslyDisableSandbox. In bypass mode that retry runs without asking. - Unsupported platforms. Where the sandbox can’t start, Claude Code runs commands without it, unless you set
failIfUnavailable. - Wide domains. Allowing all of
github.comopens a path to send data out. Anthropic also warns that allowing the Docker socket can escape the sandbox.
Anthropic calls it “not a complete isolation boundary”. It’s a strong floor for commands, not a box around Claude Code. Codex takes the other approach, with its sandbox on by default: see Codex sandbox and approval modes for a side-by-side.
Close the gaps
{
"sandbox": {
"enabled": true,
"failIfUnavailable": true,
"allowUnsandboxedCommands": false,
"filesystem": {
"denyRead": ["~/.ssh", "~/.aws", "~/.config/gcloud", "~/.kube"]
},
"network": {
"allowedDomains": ["registry.npmjs.org"]
}
},
"permissions": {
"deny": ["Read(~/.ssh/**)", "Read(~/.aws/**)"],
"ask": ["Bash(dangerouslyDisableSandbox:true)"]
}
}
failIfUnavailablestops instead of running unsandboxed.allowUnsandboxedCommands: falseturns off the retry outside the box. Theaskrule makes any retry ask, even in auto or bypass mode.denyReadcovers commands; the matchingReaddeny rules cover Claude’s own Read tool.- Keep
allowedDomainsto what the task needs: your package registry, your API. - Start Claude Code from a shell without production secrets in its environment.
When you need the whole thing in a box
To cover file tools, MCP servers and hooks too, run all of Claude Code inside isolation:
- Anthropic’s dev container: a reference container with a firewall script. Run it as a non-root user and don’t mount
~/.sshor cloud credentials. - sandbox-runtime (
srt): the same Seatbelt and bubblewrap layer as a standalone tool that can wrap a whole agent or an MCP server. It’s a research preview. - A VM for unattended runs with
--dangerously-skip-permissions.
Anthropic’s warning for containers: with skip-permissions, a malicious project can still send out anything inside the container, Claude Code’s own login included.
Safe default to paste
claude/user-settings.json in the coral-safety-kit turns the sandbox on, turns off the retry outside it, turns off bypass mode and denies reading ~/.ssh and cloud credentials. Merge it into ~/.claude/settings.json, then run /sandbox to check it’s on.
Where Coral fits
With the sandbox on and the retry off, Claude asks when a command needs to leave the box, and that question waits until you see it. Coral puts it in your Mac’s notch with the full command, and you answer with one key. Free on your Mac; answering from your iPhone straight to the agent is Pro.
Coming in Coral Terminal: Guard, which shows what a risky command would really do before you answer, and isolation levels per agent.
Questions
What is the Claude Code sandbox?
An operating-system boundary around the commands Claude runs: Seatbelt on macOS, bubblewrap on Linux. Commands can write only in the project and temp folders and reach only allowed domains. Turn it on with /sandbox.
How do I sandbox Claude Code?
Run /sandbox, or set "sandbox": { "enabled": true } in ~/.claude/settings.json. To cover everything, including file tools and MCP servers, run Claude Code in a dev container or VM.
Does the sandbox protect my SSH keys?
Not by default. Sandboxed commands can read most of your machine. Add ~/.ssh to sandbox.filesystem.denyRead, and a Read(~/.ssh/**) deny rule for Claude’s own Read tool.
Does the sandbox work with --dangerously-skip-permissions?
Yes, and it’s a much safer pair than skip-permissions alone. Set allowUnsandboxedCommands to false, because in bypass mode a retry outside the sandbox runs without asking.
Does the Claude Code sandbox work on Windows?
Not natively. It works on macOS, Linux and WSL2. On native Windows, commands run unsandboxed.