What does the Claude Code sandbox block by default?
Writes outside your project and direct network connections. Reads are another matter: a sandboxed command can still read most of the machine, including ~/.ssh and ~/.aws/credentials, until you deny them.
| Access | Default inside the sandbox | Change it with |
|---|---|---|
| Writes | Working directory, a per-user temp directory, directories you added | filesystem.allowWrite, denyWrite |
| Reads | Most of the machine, credential files included | filesystem.denyRead, credentials |
| Network | Only through a local proxy; allowed domains start empty | network.allowedDomains, deniedDomains |
| Environment | Inherited, secrets included | credentials, CLAUDE_CODE_SUBPROCESS_ENV_SCRUB |
All keys sit under sandbox in a settings file. From Claude Code's sandboxing docs, read December 1, 2026.
The limits apply to Bash, PowerShell and Monitor commands and every process they start. Claude Code builds the sandbox on the open-source @anthropic-ai/sandbox-runtime package.
How do you turn on the Claude Code sandbox?
Run /sandbox in a session and pick a mode. On Linux and WSL2, install bubblewrap and socat first; the panel's Dependencies tab shows what is missing. Native Windows has no sandbox: run Claude Code inside WSL2.
- Run
/sandbox. The panel has Mode, Overrides and Config tabs. - On Mode, choose auto-allow (sandboxed commands run without a prompt) or regular permissions (every command still asks).
- Ask Claude to run a build or tests. The first time a command needs a new host, Claude Code asks you to approve it.
The panel saves to .claude/settings.local.json, for this project only. For every project, put "sandbox": {"enabled": true} in ~/.claude/settings.json. For one session only:
claude --settings '{"sandbox": {"enabled": true, "allowUnsandboxedCommands": false}}'
What runs outside the sandbox?
Everything that isn't a shell command Claude runs. The docs list:
- The Read, Edit, Write, WebFetch and WebSearch tools, which follow permission rules instead:
denyReaddoesn't stop Read, andallowedDomainsdoesn't limit WebFetch. - Hooks, local MCP servers, plugin monitors, LSP servers, your status line command and
apiKeyHelper, with your full access. - Commands you type at the
!prompt, in most sessions. - Commands matching
excludedCommands, and retries Claude runs unsandboxed.
To put all of that behind one boundary, run the Claude Code process itself in a container, a virtual machine or the sandbox runtime; Docker Sandboxes and E2B are compared here.
How do you stop Claude retrying a command outside the sandbox?
Set allowUnsandboxedCommands to false; the Overrides tab calls it strict sandbox mode. Without it, a command that fails in the sandbox can be retried with dangerouslyDisableSandbox: you get a prompt in Manual and acceptEdits modes, a classifier decides in auto mode, and in bypassPermissions mode it runs with no prompt. Codex asks for approval instead: how Codex sandbox approvals work.
Also set failIfUnavailable: by default, when the sandbox can't start, Claude Code runs commands unsandboxed. To require both for every developer, deliver them in managed settings:
{
"sandbox": {
"enabled": true,
"failIfUnavailable": true,
"allowUnsandboxedCommands": false
}
}
With the retry turned off in managed settings, Claude Code ignores a repository's settings that would loosen the sandbox, excludedCommands included. On native Windows, failIfUnavailable makes Claude Code exit at startup.
How do you keep sandboxed commands away from your keys?
List them in sandbox.credentials. There is no built-in deny list, so only what you name is protected; a five-line credential audit shows what to name:
{
"sandbox": {
"enabled": true,
"credentials": {
"files": [
{ "path": "~/.aws/credentials", "mode": "deny" },
{ "path": "~/.ssh", "mode": "deny" }
],
"envVars": [
{ "name": "GITHUB_TOKEN", "mode": "deny" }
]
}
}
}
Denied files can't be read; denied variables are unset before each sandboxed command. A deny entry from any settings scope only narrows access, and no scope can remove one another scope added.
How many MCP servers ask Claude Code for a key?
19,778 of the 78,793 active servers in the official MCP Registry on December 2, 2026 ask for an API key, token or password. Local MCP servers run outside the sandbox with your full access, and sandbox.credentials covers only sandboxed commands, so a key you hand a server is that server's to use.
Give each server a key made for it alone, with the narrowest scope it offers, and prefer servers that sign in with OAuth. The servers that declare a secret are counted in the MCP Registry secrets dataset, mcp-registry-servers-with-secrets-2026-12.csv, and every active server is counted in mcp-registry-counts-2026-12.csv (CC BY 4.0); the AI agent security guide sums it up.
Which files stay write-protected inside the project?
The ones Claude Code loads settings and code from, even where commands may write: .claude settings and its skills, agents, commands and hooks folders, .mcp.json, shell startup files, .gitconfig, and hooks and config inside .git. An allowWrite entry doesn't lift this. A command that could edit them could grant itself permissions or add a hook that runs outside the sandbox.
How do you check the sandbox is working?
Ask Claude, not the ! prompt, to run these two lines. If Claude asks to retry outside the sandbox, decline.
| Command | Result when sandboxed |
|---|---|
touch ~/sandbox-probe | Operation not permitted on macOS; Read-only file system on Linux and WSL2 |
curl --noproxy '*' https://example.com | Could not resolve host |
From Claude Code's sandboxing docs, read December 1, 2026.
How was this page checked?
Every default, setting and command was read from Claude Code's documentation on December 1, 2026. Errors: support@winding.ai.
- Configure the sandboxed Bash tool (Claude Code docs): defaults, what runs outside, modes, retries, strict mode, credentials, protected paths, managed settings, checks
- anthropics/sandbox-runtime on GitHub