Short answer
The Claude Code sandbox is a built-in boundary, enforced by the operating system, around the shell commands Claude runs. It limits where they can write and which network hosts they can reach. Turn it on with /sandbox. It works on macOS, Linux and WSL2, and it does not cover Claude's file tools, MCP servers or hooks.
What the Claude Code sandbox is
Anthropic's sandboxing documentation describes a boundary the operating system enforces around the shell commands Claude runs on your machine. You set which files and network domains they can reach. It covers Bash, PowerShell and Monitor commands and every process they start, is off by default, and is built on the open-source @anthropic-ai/sandbox-runtime package.
Permission checks happen before a command runs, from its text. The operating system enforces the sandbox on the running process, so it holds whatever the model chose to run. Anthropic's engineering post says it cuts permission prompts by 84% in Anthropic's internal usage. The defaults:
| Access | Default inside the sandbox | Change it with |
|---|---|---|
| Writes | The working directory, a per-user temp directory and directories you added. Protected paths stay denied | filesystem.allowWrite, denyWrite |
| Reads | Most of the machine, including ~/.ssh and ~/.aws/credentials | filesystem.denyRead, allowRead, credentials |
| Network | No direct route. A proxy on your machine checks each host against your allowed domains, which start empty | network.allowedDomains, deniedDomains |
| Environment variables | Inherited from Claude Code, secrets included | credentials |
There is no built-in credential deny list: only files and variables you name are restricted.
What the sandbox does not cover
The sandbox wraps shell commands and nothing else:
| What | Inside the sandbox? | What governs it instead |
|---|---|---|
| Bash, PowerShell and Monitor commands, and the processes they start | Yes | Sandbox settings |
| Read, Edit, Write, WebFetch and WebSearch tools | No | Permission rules. denyRead does not stop the Read tool, and allowedDomains does not limit WebFetch |
Command hooks, local MCP servers, plugin monitors, LSP servers, your status line command, apiKeyHelper | No | Nothing: they run with your full access |
Commands you type at the ! prompt, excludedCommands matches and unsandboxed retries | Usually no | You, or the regular permission flow |
So a hook or a local MCP server runs with your full access even with the sandbox on. Subagents share the parent's sandbox configuration, so their Bash commands are sandboxed. To put everything behind one boundary, run the whole Claude Code process in a container, a VM or the sandbox runtime.
For an outer boundary that is a computer other than your laptop, Claude Code on Hivra runs the official CLI on a cloud computer of its own. The built-in sandbox is a Claude Code feature you can try there, and Hivra does not set it up for you.
Which systems support it and what to install
| Platform | What enforces it | What you install |
|---|---|---|
| macOS | Seatbelt, built in | Nothing |
| Linux and WSL2 (not WSL1) | bubblewrap | bubblewrap and socat |
| Native Windows | Not supported: commands run unsandboxed | Run Claude Code inside WSL2 |
On Linux and WSL2 the sandbox needs bubblewrap for filesystem isolation and socat to relay network traffic to the proxy:
Restart Claude Code afterwards, because the dependency check runs at startup. An optional seccomp filter adds Unix socket blocking: npm install -g @anthropic-ai/sandbox-runtime installs it if the Dependencies tab lists it.
If the platform is unsupported or the dependency check fails, Claude Code runs commands without the sandbox. Set sandbox.failIfUnavailable to true to make it refuse to start instead.
How to turn the Claude Code sandbox on
1. Run /sandbox in a session. The panel has a Mode tab, an Overrides tab (whether a failed command may fall back to running unsandboxed) and a Config tab. If a Dependencies tab is the only one, the sandbox cannot start: fix what it lists, restart and try again.
2. Pick a mode. Your choice is saved to .claude/settings.local.json for the project. To sandbox every project, set sandbox.enabled to true in ~/.claude/settings.json. To try it for one session, use --settings:
That session cannot retry a blocked command outside the sandbox.
3. Check it works. Ask Claude to run these two commands. Do not type them at the ! prompt, where commands usually run outside the sandbox.
| Command | Result inside the sandbox |
|---|---|
touch ~/sandbox-probe | Fails with Operation not permitted on macOS, or Read-only file system on Linux and WSL2 |
curl --noproxy '*' https://example.com | Fails with Could not resolve host |
If Claude offers to retry outside the sandbox, decline.
Auto-allow mode or regular permissions
Both modes enforce the same limits. In auto-allow, a command inside the sandbox needs no prompt. In regular mode, every Bash command still goes through the permission flow.
Auto-allow works independently of your permission mode, with exceptions for plan mode and for auto mode, where the classifier can still review a command. So even in Manual mode, Bash commands that change files inside the boundary run without a prompt, where the edit tools would ask. Deny rules still block, rm aimed at a critical path still goes through the regular flow, and ask rules such as Bash(git push *) still prompt.
This is not auto mode, where a classifier reviews actions. The two can be combined.
Filesystem and network rules
Writes. When a tool such as kubectl, terraform or npm needs to write outside the working directory, grant that one path instead of excluding the tool:
On Linux and WSL2 an entry for a path that does not exist yet has no effect, so create it first. Sandbox paths use standard conventions (/tmp/build is absolute, ~/.kube is relative to home), unlike Read and Edit permission rules, which use //path for absolute.
Reads. denyRead blocks, allowRead re-opens, and the narrower path wins. A deny holds inside a wider allow, so "allowRead": ["~/"] with "denyRead": ["~/.env"] keeps ~/.env blocked. An allowWrite entry does not override this: the sandbox denies writes to the files Claude Code loads configuration from, such as the .claude settings files, .mcp.json, .bashrc and hooks inside .git, so a command cannot give itself permissions or add a hook. Only filesystem.disabled, which turns off all filesystem isolation, or allowNestedUserNamespaces on Linux and WSL2 removes that protection.
Network. A sandboxed command has no direct route out, and a proxy checks each hostname against your lists. Tools that read proxy variables, like curl, npm and git over HTTPS, connect once the host is allowed. Plain ssh and most database drivers ignore them and cannot connect even to an allowed host.
When a command reaches an unlisted host, your permission mode decides. Manual and acceptEdits prompt you. bypassPermissions allows it without a prompt. Auto mode refuses unless the command named the host and the classifier approved. dontAsk refuses. With strictAllowlist on, unlisted hosts are refused in every mode.
Every sandbox setting in one table
From Anthropic's settings reference. When an administrator makes the sandbox admin-required, Claude Code ignores loosening keys such as excludedCommands in a project's .claude/settings.json.
| Setting | What it does | Who can set it |
|---|---|---|
sandbox.enabled | Turns the sandbox on. Unset means off | Any file |
sandbox.autoAllowBashIfSandboxed | true is auto-allow mode, false is regular permissions | Any file |
sandbox.failIfUnavailable | Exit at startup instead of running unsandboxed | Any file |
sandbox.allowUnsandboxedCommands | false ignores the retry parameter (strict mode) | Any file |
sandbox.excludedCommands | Patterns that run outside the sandbox | Any file |
sandbox.filesystem.allowWrite / denyWrite | Extra writable paths / paths never writable | Any file |
sandbox.filesystem.denyRead / allowRead | Paths that cannot be read / re-opens a denied region | Any file |
sandbox.network.allowedDomains / deniedDomains | Hosts allowed without a prompt (wildcards and :port work) / hosts always blocked | Any file |
sandbox.network.strictAllowlist | Deny unlisted hosts instead of prompting | User or managed |
sandbox.credentials | Deny reads of named files, unset named variables | Any file |
sandbox.allowNestedUserNamespaces | Linux: let commands create user namespaces. Turns off a security boundary | User or managed |
Worked configs you can copy
1. Everyday setup. Anthropic's own example: auto-allow, docker outside the sandbox, two write paths, your AWS credentials file hidden, and GitHub and npm pre-allowed:
2. Require it. For an organization, deliver this through managed settings. Claude Code then refuses to start where the sandbox cannot run, and Claude cannot retry a blocked command outside it:
This makes the sandbox admin-required, so a repository can no longer take commands out of it. Put the excludedCommands entries your approved tools need in the managed file. A developer can still type a command at the ! prompt and run it outside the sandbox. To protect secrets, add sandbox.credentials entries that deny reads of files such as ~/.ssh.
The unsandboxed retry and excluded commands
The unsandboxed retry. When a command fails inside the sandbox, Claude may retry it with the dangerouslyDisableSandbox parameter, and the retry runs with no sandbox. In bypassPermissions mode it runs without a prompt. In Manual and acceptEdits you get a prompt titled "Bash command (unsandboxed)". Auto mode sends it to a classifier, and dontAsk denies it. A matching allow rule such as Bash(curl *) approves it silently. To be asked every time, add an ask rule for Bash(dangerouslyDisableSandbox:true). To remove the hatch, set allowUnsandboxedCommands to false (strict sandbox mode).
Excluded commands run outside the sandbox with no filesystem limits and no proxy. End the pattern with *, because a pattern with no wildcard is an exact match, so docker matches only docker with no arguments. Every command in a chained call must match, so npm ci && docker compose build stays sandboxed unless npm ci is covered too. Excluded commands still go through the regular permission flow.
Anthropic calls exclusion a convenience, not a security boundary. If a tool needs one more directory or host, allowWrite or allowedDomains keeps it sandboxed.
What the sandbox breaks and how to fix it
Some commands fail inside the sandbox that work outside it:
| What you see | Fix |
|---|---|
| Host-not-allowed error | Approve the host at the prompt or add it to allowedDomains |
jest hangs | watchman is incompatible. Run jest --no-watchman |
docker fails | Incompatible with the sandbox. Exclude what you need, such as docker compose * |
gh, gcloud or terraform fail TLS checks on macOS | Add a pattern such as gh * to excludedCommands |
A database client or plain ssh cannot reach an allowed host | The tool ignores the proxy variables. Exclude the command and add an ask rule so you approve each run |
Ubuntu's AppArmor restriction is the Linux failure to know. If Claude Code reports that it stops bubblewrap, or commands fail with bwrap: setting up uid map: Permission denied, add a profile. This is Anthropic's command for /usr/bin/bwrap (check with which bwrap):
Restart Claude Code and run the two probe commands again.
Git over SSH on macOS can fail even with the host allowed. Switch the remote to HTTPS, which needs credentials such as a personal access token:
On Linux and WSL2 it works once the host is allowed on port 22.
Sandbox vs permission modes vs dev containers vs the skip flag
The sandbox is not a permission mode. Permission modes decide whether a tool call runs. The sandbox restricts what a Bash command can reach once it runs. They are complementary layers:
| Approach | What it controls | Covers MCP servers and hooks? |
|---|---|---|
| Permission modes, including auto mode | Whether a tool call runs, and who is asked | No boundary |
--dangerously-skip-permissions | Nothing: the prompts are off | No boundary |
| Built-in Bash sandbox | What a Bash command can read, write and reach | No |
Sandbox runtime (srt claude) | The whole Claude Code process | Yes. A beta research preview |
| Dev container | The whole development environment | Yes. Needs Docker |
| Virtual machine | A full operating system with its own kernel | Yes. The strongest separation |
| A separate cloud computer such as Hivra's | Keeps the whole session off your laptop | Everything runs on that computer, not on your laptop |
Does the sandbox make --dangerously-skip-permissions safe? Anthropic says no. With that flag no prompt is left to catch a mistake, so the docs say to always run it inside a container, a VM or the sandbox runtime, so file tools, MCP servers and hooks sit inside the boundary too. The sandboxed Bash tool alone is not sufficient for fully unattended runs in auto mode or bypass mode. Even in a dev container, the flag does not stop a malicious project from exfiltrating anything inside it, including the credentials in ~/.claude. Our skip-permissions guide covers what the flag skips.
You can layer them: the sandboxed Bash tool inside a container or VM adds command limits on top of the outer boundary.
Security limits to know before you rely on it
Anthropic says sandboxing reduces risk and is not a complete isolation boundary. Its listed limits:
- Hostname filtering. The proxy does not inspect TLS by default. A broad domain such as
github.comcan create paths for data exfiltration, and domain fronting could reach hosts outside your list. - Unix sockets and broad writes. Allowing
/var/run/docker.sockeffectively grants access to the host system, and writable directories holding$PATHexecutables or shell startup files can lead to code running in another security context. - Weaker modes.
enableWeakerNestedSandboxconsiderably weakens security, andallowNestedUserNamespacescan let code end up outside the sandbox. - Computer use works on your real desktop.
Running Claude Code with a sandbox on a Hivra computer
The sandbox limits shell commands on whichever machine Claude Code runs on. Where it runs is a separate choice, and it can give you an outer layer. Hivra runs the official Claude Code CLI on a cloud computer of its own, separate from your laptop, and you reach its terminal and files from a browser on any device. If you turn the sandbox on there, it limits Bash commands, while the computer keeps the whole session, including the file tools, MCP servers and hooks the sandbox does not wrap, off your laptop.
- You are not locked into one agent. The same Hivra account launches Hermes, OpenClaw, Codex and Agent Zero as well as Claude Code, each on a computer of its own, and you reach them from a browser on any device. The sandbox is a Claude Code feature, so the others have their own safety settings, but you can try one beside Claude Code without a new account or server.
- Your laptop stays out of it. A bad command, or an
excludedCommandsentry that was too broad, lands on the Hivra computer, not your personal machine.
Hivra-run computers require a paid plan unless you're admitted through gated, capacity-limited token-holder access for supported computers. Paid plans start at $9.99 a month for 2 vCPU and 4 GB of RAM. You can sign in to Claude Code with your own Anthropic account, or launch it on Hivra credits. Hivra hosting does not include or replace your Anthropic subscription or usage, and Hivra is not affiliated with Anthropic.
Honest limits: Hivra does not turn the sandbox on or configure it for you, and we have not checked whether bubblewrap, socat or user namespaces work on a Hivra computer, or how /sandbox behaves in Hivra's Chat. Run /sandbox in the Terminal tab and the panel tells you what is missing. A separate computer is not a security guarantee: whatever you sign in to on it is within the agent's reach, and Hivra administrators retain infrastructure access to managed hosts, so a machine you run yourself gives you more control. At your desk, the built-in sandbox alone is simpler.
Launch Claude Code on Hivra if you want the agent on a computer that is not yours. Our Claude Code on Linux guide covers building the server yourself.
Which setup should you pick
On your own machine, use the sandbox in auto-allow mode with credentials denied and a short allowlist. For a team, require it through managed settings. For unattended runs with the skip flag, use a container, VM or the sandbox runtime, as a non-root user, on trusted repositories. For Claude Code off your laptop, use a cloud computer such as Hivra's, and turn the sandbox on yourself if you want it as a second layer. Whichever you choose, treat every excludedCommands entry as a hole you chose to cut.
Common questions
What is the Claude Code sandbox?
A boundary the operating system enforces around the shell commands Claude Code runs. You set which files and network domains they can reach. It is off by default.
How do I enable the Claude Code sandbox?
Run /sandbox in a session and pick a mode, or set sandbox.enabled to true in ~/.claude/settings.json. On Linux and WSL2, install bubblewrap and socat first and restart Claude Code. macOS needs nothing extra.
Does the Claude Code sandbox work on Windows?
Not natively: there, Claude Code runs commands unsandboxed. Run Claude Code inside a WSL2 distribution instead. WSL1 is not supported.
Is the sandbox enough to run --dangerously-skip-permissions?
No. Anthropic says to run that flag inside a container, a VM or the sandbox runtime, and calls the sandboxed Bash tool alone not sufficient for unattended runs.
Why does Docker not work in the Claude Code sandbox?
Anthropic says docker is incompatible with the sandbox. Exclude the commands you need with a pattern such as docker compose * in excludedCommands. They then run with your full access, so keep it narrow.
Does the sandbox cover MCP servers and hooks?
No. Command hooks, local MCP servers and helper commands such as your status line run outside it with your full access. The Read, Edit and WebFetch tools follow permission rules instead.
Can I use the Claude Code sandbox on Hivra?
Hivra runs the official Claude Code CLI on a cloud computer of its own, and you can run /sandbox in the Terminal tab to see whether anything is missing. Hivra does not turn the sandbox on or configure it for you, and we have not checked whether its dependencies work on a Hivra computer. Hivra is not affiliated with Anthropic.