Hivra
A boundary the operating system enforces, around the shell commands Claude runs.

Claude Code sandbox: what it blocks, how to turn it on and what it breaks

With the sandbox off, which is the default, the shell commands Claude Code runs have the same access to your files and network as any program you run yourself, limited only by the permission prompts. The built-in sandbox adds a limit the operating system enforces while a command runs. This guide covers what it blocks and what it leaves alone, how to turn it on, every setting that matters, the fixes for what it breaks, and how it compares with permission modes, dev containers and the skip-permissions flag. Details are as of November 2026, and some settings need a recent Claude Code version, so run claude --version.

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:

AccessDefault inside the sandboxChange it with
WritesThe working directory, a per-user temp directory and directories you added. Protected paths stay deniedfilesystem.allowWrite, denyWrite
ReadsMost of the machine, including ~/.ssh and ~/.aws/credentialsfilesystem.denyRead, allowRead, credentials
NetworkNo direct route. A proxy on your machine checks each host against your allowed domains, which start emptynetwork.allowedDomains, deniedDomains
Environment variablesInherited from Claude Code, secrets includedcredentials

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:

WhatInside the sandbox?What governs it instead
Bash, PowerShell and Monitor commands, and the processes they startYesSandbox settings
Read, Edit, Write, WebFetch and WebSearch toolsNoPermission 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, apiKeyHelperNoNothing: they run with your full access
Commands you type at the ! prompt, excludedCommands matches and unsandboxed retriesUsually noYou, 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

PlatformWhat enforces itWhat you install
macOSSeatbelt, built inNothing
Linux and WSL2 (not WSL1)bubblewrapbubblewrap and socat
Native WindowsNot supported: commands run unsandboxedRun Claude Code inside WSL2

On Linux and WSL2 the sandbox needs bubblewrap for filesystem isolation and socat to relay network traffic to the proxy:

bash
# Ubuntu or Debian sudo apt-get install bubblewrap socat # Fedora sudo dnf install bubblewrap socat

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:

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

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.

CommandResult inside the sandbox
touch ~/sandbox-probeFails with Operation not permitted on macOS, or Read-only file system on Linux and WSL2
curl --noproxy '*' https://example.comFails 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:

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

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.

SettingWhat it doesWho can set it
sandbox.enabledTurns the sandbox on. Unset means offAny file
sandbox.autoAllowBashIfSandboxedtrue is auto-allow mode, false is regular permissionsAny file
sandbox.failIfUnavailableExit at startup instead of running unsandboxedAny file
sandbox.allowUnsandboxedCommandsfalse ignores the retry parameter (strict mode)Any file
sandbox.excludedCommandsPatterns that run outside the sandboxAny file
sandbox.filesystem.allowWrite / denyWriteExtra writable paths / paths never writableAny file
sandbox.filesystem.denyRead / allowReadPaths that cannot be read / re-opens a denied regionAny file
sandbox.network.allowedDomains / deniedDomainsHosts allowed without a prompt (wildcards and :port work) / hosts always blockedAny file
sandbox.network.strictAllowlistDeny unlisted hosts instead of promptingUser or managed
sandbox.credentialsDeny reads of named files, unset named variablesAny file
sandbox.allowNestedUserNamespacesLinux: let commands create user namespaces. Turns off a security boundaryUser 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:

json
{ "sandbox": { "enabled": true, "autoAllowBashIfSandboxed": true, "excludedCommands": ["docker *"], "filesystem": { "allowWrite": ["/tmp/build", "~/.kube"], "denyRead": ["~/.aws/credentials"] }, "network": { "allowedDomains": ["github.com", "*.npmjs.org"] } } }

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:

json
{ "sandbox": { "enabled": true, "failIfUnavailable": true, "allowUnsandboxedCommands": false } }

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 seeFix
Host-not-allowed errorApprove the host at the prompt or add it to allowedDomains
jest hangswatchman is incompatible. Run jest --no-watchman
docker failsIncompatible with the sandbox. Exclude what you need, such as docker compose *
gh, gcloud or terraform fail TLS checks on macOSAdd a pattern such as gh * to excludedCommands
A database client or plain ssh cannot reach an allowed hostThe 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):

bash
sudo tee /etc/apparmor.d/bwrap > /dev/null <<'EOF' abi <abi/4.0>, include <tunables/global> profile bwrap /usr/bin/bwrap flags=(unconfined) { userns, include if exists <local/bwrap> } EOF sudo systemctl reload apparmor

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:

bash
git remote set-url origin https://git.example.com/example-org/example-repo.git

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:

ApproachWhat it controlsCovers MCP servers and hooks?
Permission modes, including auto modeWhether a tool call runs, and who is askedNo boundary
--dangerously-skip-permissionsNothing: the prompts are offNo boundary
Built-in Bash sandboxWhat a Bash command can read, write and reachNo
Sandbox runtime (srt claude)The whole Claude Code processYes. A beta research preview
Dev containerThe whole development environmentYes. Needs Docker
Virtual machineA full operating system with its own kernelYes. The strongest separation
A separate cloud computer such as Hivra'sKeeps the whole session off your laptopEverything 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.com can create paths for data exfiltration, and domain fronting could reach hosts outside your list.
  • Unix sockets and broad writes. Allowing /var/run/docker.sock effectively grants access to the host system, and writable directories holding $PATH executables or shell startup files can lead to code running in another security context.
  • Weaker modes. enableWeakerNestedSandbox considerably weakens security, and allowNestedUserNamespaces can 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 excludedCommands entry 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.

Give your agent a computer that stays on.

From $9.99/mo. Bring your own AI key. 7-day money-back guarantee on card payments.

Start Now