Learning resourcesReviewed · Anthropic

Claude Code: Configure the sandboxed Bash tool

This is the vendor documentation page for the Bash sandbox built into Claude Code. It is written for developers and administrators who use Claude Code on macOS, Linux or WSL2. The main catch is that the sandbox is off by default and covers shell commands only. The page explains how to turn the sandbox on, which files and network hosts sandboxed commands can reach by default, and how to widen or narrow that boundary. It also covers enforcing the sandbox with managed settings, fixing common breakages, and where the protection stops.

Researched 14 Nov 2026

In short.

This is the vendor documentation page for the Bash sandbox built into Claude Code. It is written for developers and administrators who use Claude Code on macOS, Linux or WSL2, and the main catch is that the sandbox is off by default and covers shell commands only. The page describes a boundary that the operating system enforces around the shell commands Claude runs (Bash, PowerShell and Monitor) and the processes they start. By default those commands can write only to the working directory, a per-user temp directory and added directories. They can reach the network only through a local proxy whose list of allowed domains starts empty. Reads are broad by default and include credential files, so the page tells you to add credential protection yourself. The page documents two approval modes, an escape hatch that retries a failed command outside the sandbox, excluded commands, settings that deny or mask credentials, managed-settings enforcement for organisations, and a long troubleshooting list. It also states plainly what runs outside the sandbox: Claude's file and web tools, hooks, local MCP servers, LSP servers and other helper processes. Nothing was run for this report. Everything below comes from reading the captured page, and no behaviour was tested.

Researched and written by an AI model and checked by a second AI model. How it works

This report covers the single documentation page at [https://code.claude.com/docs/en/sandboxing.md], as captured on 14 November 2026. Linked pages are excluded, including the settings reference, permissions, permission modes, sandbox environments, the sandbox-runtime repository and the bubblewrap and socat projects. The page text contains no licence or reuse notice. The page's reuse terms, the cost of Claude Code and the licences of linked projects are unknown from this evidence. No command, setting or example was executed, so none of the described behaviour has been tested.

The overview

What this is

The resource is one documentation page titled Configure the sandboxed Bash tool, at [https://code.claude.com/docs/en/sandboxing.md]. Its address and content suggest it is the Claude Code vendor's own documentation. It is not a software package, a plugin or a configuration file you install. It describes a feature built into Claude Code and shows the settings that control it.

The page describes itself this way: restrict the files and network hosts Claude Code's shell commands can reach with the built-in sandbox, turn it on, set the boundary, and fix what it breaks. It links to many other pages, such as the settings reference, permissions and permission modes. Those linked pages were not reviewed and are not covered here.

Assessment

For anyone who lets Claude Code run shell commands on a real machine, this page is a thorough and unusually candid reference. It gives exact defaults, names the setting that changes each default, includes ready-to-copy JSON examples, and has its own Limitations section. Early on, it states what the sandbox does not cover, which helps readers avoid assuming more protection than they have.

Its main weaknesses affect readability, not accuracy. The page is long and dense, with many cross-references and notes tied to specific versions. Some settings behave differently depending on platform, settings scope and permission mode, so a beginner may need several passes. Because it is vendor documentation, its claims about how the sandbox behaves were not independently checked here.

Who it is for

Individual developers who use Claude Code and want to limit what its shell commands can write or connect to. The Get started steps and the confirmation probes suit them.

Platform, security and IT administrators who want to require sandboxing across an organisation. A whole section covers managed settings, locks that stop developers widening the policy, how repository settings are treated when the sandbox is admin-required, and custom proxies.

People who hit a specific failure, such as jest hanging, docker commands failing, bubblewrap errors on Ubuntu, git over SSH failing on macOS, or a database client that cannot connect. The troubleshooting section is organised by symptom.

The built-in sandbox does not run on native Windows; Windows users can follow the page's guidance for running Claude Code inside WSL2. On native Windows, the page says Claude Code runs commands unsandboxed. WSL1 is also not supported.

What the sandbox can do, as documented

Filesystem limits: by default, sandboxed commands can write to the working directory, a per-user temp directory and directories you have added. Protected paths stay write-denied even inside those directories. These include Claude Code settings files, the skills, agents, commands and hooks directories, .mcp.json, shell startup files such as .bashrc and .zshrc, and .gitconfig. You can add write paths with allowWrite and deny reads or writes with denyRead and denyWrite. You can re-allow reads inside a denied region with allowRead, and the narrower path wins when rules overlap.

Network limits: commands have no direct route out. Traffic goes through a proxy on your machine that checks each hostname against allowed and denied domains, and the allowed list starts empty. Your permission mode decides what happens to other hosts: you get a prompt, the connection is refused automatically, or it is allowed. The strictAllowlist and allowManagedDomainsOnly settings make the proxy refuse other hosts in every mode.

Credential handling: sandbox.credentials can deny reads of named files and unset named environment variables before each sandboxed command runs. File deny entries belong to the filesystem layer, so they stop applying if you disable filesystem isolation. A mask mode works differently for each type of entry. For a masked environment variable, sandboxed commands see a per-session placeholder called the sentinel, and the proxy swaps in the real value on outbound requests to allowed hosts. For a masked file, sandboxed commands on Linux and WSL2 read a copy that contains the sentinel. On macOS, Claude Code blocks the file instead, so tools that authenticate with that file do not work inside the sandbox.

Masking has three requirements. You need the experimental network.tlsTerminate setting. Each destination must also be reachable through allowedDomains. And the entries must come from a trusted settings scope, meaning user settings, managed settings or the --settings flag, not a repository's own settings files. Without TLS termination, the sentinel reaches the server unchanged and authentication fails.

A mask entry does not always hide the credential. If the pattern finds nothing to mask in a file, the default onExtractNoMatch value, warn, skips the entry, and sandboxed commands can read the real file unmasked. On macOS, this only takes effect when filesystem isolation is off. Claude Code also treats some mask entries as deny entries because it cannot mask them safely: directories, glob patterns, files larger than 8 MiB and files that are not UTF-8 text. There is no built-in list of credentials to deny, so only the files and variables you list are restricted.

Approval modes: auto-allow normally approves sandboxed Bash commands, subject to documented exceptions. A command that a Bash deny rule matches is still blocked. Content-scoped ask rules such as Bash(git push *) still force a prompt. rm or rmdir commands that target a critical path go through the regular permission flow. Monitor tool commands are not approved automatically. Some command forms also go through the regular permission flow, such as a leading variable assignment like FOO=bar npm test, make CC=clang, or eval "ls".

Auto-allow also behaves differently in two permission modes. In plan mode it does not widen approvals. In auto mode, a command that carries its own list of allowed domains goes to the classifier, and sandboxed commands can also go through server-side classifier review. In regular permissions mode, every Bash command goes through the regular permission flow even when it is sandboxed, so your permission rules and permission mode decide whether a prompt appears.

Other documented features: an escape hatch that retries a failed command unsandboxed, which you can turn off with strict sandbox mode (allowUnsandboxedCommands set to false); excludedCommands for tools that cannot run in the sandbox; per-command allowed domains in auto mode; an option to disable filesystem isolation while keeping network isolation; and custom proxy ports.

Organisations can enforce the sandbox through managed settings by setting sandbox.enabled to true, sandbox.failIfUnavailable to true and sandbox.allowUnsandboxedCommands to false. If failIfUnavailable is not set to true, Claude Code falls back to running commands unsandboxed when the sandbox is unavailable.

Using it

Requirements

Platform: the sandbox runs on macOS, Linux and WSL2. On macOS it uses the built-in Seatbelt framework, so nothing extra is needed. On Linux and WSL2 it needs bubblewrap and socat, which you can install with apt-get on Ubuntu or Debian and dnf on Fedora. An optional seccomp filter, installed with npm install -g @anthropic-ai/sandbox-runtime, adds blocking of Unix domain sockets. Ripgrep is bundled with the native Claude Code binary. The dependency check runs at startup, so you must restart Claude Code after installing packages.

On Ubuntu, an AppArmor restriction on unprivileged user namespaces can stop bubblewrap. The page offers two fixes: an AppArmor profile for /usr/bin/bwrap, or a sysctl change that lifts the restriction for every program until the next reboot.

Version notes: the page gives minimum Claude Code versions for many features. Examples are v2.1.219 for strictAllowlist, v2.1.221 for file masking, v2.1.271 for per-command allowed domains, v2.1.285 for the rules on repository settings under an admin-required sandbox, and v2.1.305 for allowNestedUserNamespaces. The page mentions behaviour changes up to v2.1.310. Which version a given reader has installed is unknown.

Claude Code itself is required. This page does not say what plan, account or subscription Claude Code needs.

How it works

The operating system enforces the boundary on the running process, so it does not depend on the model's judgement. On macOS this uses Seatbelt. On Linux and WSL2 it uses bubblewrap, and commands run in a separate network namespace with no connection to your network. Claude Code runs a sandbox proxy outside the sandbox and points commands at it through HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and related variables. The proxy checks the hostname of each connection. The sandbox is built on the open source @anthropic-ai/sandbox-runtime package, which can also be used on its own to wrap the whole Claude Code process.

The page keeps this separate from permission rules and permission modes. Permission decisions are made before a command runs, based on the command text and, in auto mode, a classifier. The sandbox restricts what the process can reach once it is running. Paths and domains from sandbox settings and from permission rules are merged into the final sandbox configuration.

Tools that read the proxy variables, such as curl, npm and git over HTTPS, connect once their host is allowed. Tools that ignore those variables, such as plain ssh and most database drivers, cannot connect even to an allowed host. UDP, HTTP/3 over QUIC and ICMP traffic cannot leave the sandbox. By default, the proxy decides from the requested hostname and does not inspect TLS traffic.

Local addresses: after a hostname passes the allowlist, the proxy refuses the connection if the name resolves only to local addresses. These include loopback addresses, link-local addresses such as the 169.254.169.254 cloud metadata endpoint, and addresses assigned to your own machine. This refusal is not universal. The names localhost and *.localhost may resolve to loopback. You can let a name reach a refused address by adding that IP address to allowedDomains, for example 127.0.0.1:8080.

The check applies only to hostnames: a connection made directly to an IP address is decided by your allowed domains and permission mode. The check is also skipped for connections sent through an upstream corporate proxy, because that proxy resolves the name. Allowed intranet hostnames that resolve to private ranges such as 10.0.0.0/8 still connect. If you set a custom proxy port, Claude Code's own network controls, including this check, stop applying to the traffic sent to that proxy.

Setup steps the page gives

On Linux or WSL2, install bubblewrap and socat first; the /sandbox panel also shows anything missing. Then start a Claude Code session and run /sandbox. The panel has three tabs: Mode, Overrides (which controls the allowUnsandboxedCommands setting) and Config (which shows the resolved settings). A Dependencies tab appears when something is missing. If it is the only tab, the sandbox cannot start.

Choose auto-allow or regular permissions on the Mode tab. The choice is saved to .claude/settings.local.json for the current project, and Claude Code adds that file to your global gitignore. To enable the sandbox in every project, set sandbox.enabled to true in ~/.claude/settings.json. To change it for one session only, start Claude Code with the --settings flag.

Next, ask Claude to run a build or test and approve network domains when prompted. The page suggests asking Claude to run two probes to confirm the sandbox is active. Typing them yourself at the ! prompt proves nothing, because commands typed there usually run unsandboxed. The first probe is touch ~/sandbox-probe, which should fail with Operation not permitted on macOS or Read-only file system on Linux and WSL2.

The second probe is a curl request to [https://example.com] that tells curl to bypass the proxy. It should fail with Could not resolve host, because the command has no route around the sandbox proxy. The exact command is on the original page. If Claude asks to retry a failed probe outside the sandbox, the page says to decline.

An important default to know before relying on the sandbox: if the platform is unsupported or the dependency check fails at startup, Claude Code runs commands without sandboxing unless sandbox.failIfUnavailable is set to true.

Worked examples from the page

Strict session: starting Claude Code with the --settings flag and the JSON {"sandbox": {"enabled": true, "allowUnsandboxedCommands": false}} gives a sandboxed session in which Claude cannot retry a blocked command outside the sandbox.

Extra write access: for tools such as kubectl or terraform that must write outside the working directory, the page enables the sandbox and sets filesystem.allowWrite to ["~/.kube", "/tmp/build"]. It recommends this over taking the tool out of the sandbox.

Protecting credentials: the page's credentials example sets mode deny on the files ~/.aws/credentials and ~/.ssh and on the environment variables GITHUB_TOKEN and NPM_TOKEN. Sandboxed commands then cannot read the files and do not receive the variables.

Organisation-wide enforcement: a managed-settings example sets enabled to true, failIfUnavailable to true and allowUnsandboxedCommands to false. The page notes that this combination makes the sandbox admin-required. An admin-required sandbox ignores the listed repository settings that widen access, such as excludedCommands, network.allowedDomains and filesystem.allowWrite entries in a repository's .claude/settings.json or .claude/settings.local.json. Administrators can configure approved exceptions centrally; user settings and CLI settings can still supply many exceptions unless managed restrictions prevent them.

These examples are copied from the documentation. None of them was run.

Assessment & evidence

Limitations and risks

Scope: the sandbox covers shell commands only. Claude's Read, Edit, Write, WebFetch and WebSearch tools follow permission rules instead, so a denyRead entry does not stop the Read tool and allowedDomains does not limit WebFetch. Hooks, local MCP servers, plugin monitors, LSP servers, the status line command, apiKeyHelper and mods run with your full access. Commands you type at the ! prompt usually run unsandboxed. Excluded commands and unsandboxed retries also run outside the sandbox.

Defaults to watch: the sandbox is off by default. Reads are broad by default and include ~/.ssh and ~/.aws/credentials. Environment variables are inherited from Claude Code. The list of allowed domains starts empty, but there is no built-in list of credentials to deny.

Security limitations the page states: by default the proxy decides from the hostname the client supplies and does not inspect TLS. Allowing broad domains such as github.com can therefore open paths for data exfiltration, and techniques such as domain fronting may get around the allowlist. Allowing Unix sockets such as /var/run/docker.sock can amount to access to the host system. Making directories on PATH or shell startup files writable can allow privilege escalation.

The enableWeakerNestedSandbox and allowNestedUserNamespaces settings weaken or remove a security boundary, and allowAppleEvents on macOS removes code-execution isolation. Disabling filesystem isolation while auto-allow is on lets a command write files that later commands run. The page says the sandbox reduces risk but is not a complete isolation boundary.

Compatibility: the page lists tools that fail or need workarounds. These include docker, watchman under jest, Go-based command-line tools on macOS, clipboard tools, git over SSH on macOS, Chromium and rootless Podman on Linux, database clients and plain ssh. Several of the fixes work by taking commands out of the sandbox. Native Windows is unsandboxed. The page does not mention performance overhead.

Evidence limit: this is vendor documentation, read as text. Whether the described behaviour holds on a given machine, Linux distribution or Claude Code version was not tested.

Reasoning behind the assessment

The page is useful because it is specific and balanced. It includes a table of defaults alongside the settings that change them. It explains why each protection exists; for example, protected paths stop a command from adding a hook or MCP server that Claude Code would then run outside the sandbox. It also repeats one warning in several places: settings that widen access can undo the protection, and the sandbox does not cover everything.

Some statements are easy to misread, and this report flags them because they affect safety. Auto-allow normally approves sandboxed Bash commands, subject to documented exceptions. Those exceptions include plan mode, Monitor commands, applicable ask and deny rules, certain command forms such as a leading variable assignment, make CC=clang or eval, and review of per-command domains in auto mode. Outside those exceptions, auto-allow can approve sandboxed commands that change files inside the boundary even in Manual mode, where the file edit tools would prompt.

A matching allow rule also approves an unsandboxed retry. The strictest setup needs allowUnsandboxedCommands set to false and failIfUnavailable set to true, and even then commands you type yourself may run outside the sandbox. Nothing in the captured text suggested the guidance was unsafe to follow, and its advice leans toward narrowing access.

Alternatives and related options

The page points to other isolation approaches without detailing them. It names dev containers, custom containers and virtual machines, which are covered on a separate Sandbox environments page. It also suggests running the Claude Code process itself in a container, a virtual machine or the standalone sandbox runtime if you want hooks, MCP servers and similar processes behind one boundary.

The page also describes bubblewrap, the unprivileged sandboxing tool the sandbox relies on for filesystem isolation on Linux and WSL2, and presents the standalone @anthropic-ai/sandbox-runtime package as a way to wrap the whole Claude Code process. None of these options was independently evaluated for this report, and their linked pages, including the Sandbox environments page and the sandbox-runtime and bubblewrap repositories, were excluded, so this report cannot compare them in detail.

Within Claude Code, permission rules, permission modes and auto mode are complementary layers, not replacements for the sandbox. The page says they work independently and can be combined. The page does not compare the sandbox with sandboxes in other coding agents.

Evidence base

This report rests on one source: the text of the documentation page at [https://code.claude.com/docs/en/sandboxing.md], captured on 14 November 2026. Every claim above comes from that text. No code or command was executed, no settings were applied, and no behaviour was tested, independently verified or benchmarked. Linked pages are excluded, including the settings reference, permission modes, sandbox environments and the sandbox-runtime repository.

Access & freshness

Costs

The page states no price for the sandbox. It describes the sandbox as built into Claude Code and mentions no separate fee. This page does not give the cost of Claude Code itself, including any plan or subscription it needs, so that cost is unknown from this evidence.

The running costs the page does describe are not monetary. They include installing bubblewrap and socat on Linux, more permission prompts in regular permissions mode, and time spent adding allowed domains or excluded commands for tools that do not work inside the sandbox. The page does not say whether enforcing the sandbox through server-managed settings carries any cloud or hosting charge.

Rights and licence

The captured page text contains no licence statement or reuse terms for the documentation itself, so the terms for copying or redistributing it are unknown from this evidence. The page links to the open source @anthropic-ai/sandbox-runtime repository and to the bubblewrap and socat projects. The captured text does not state their licences, and those linked pages were not reviewed.

The page does describe outbound traffic. Sandboxed commands connect through a local proxy that checks each hostname against your allowed and denied domains, and allowed connections can be tunnelled through an upstream corporate proxy. With the optional masking feature, the proxy swaps real credentials into outbound requests to permitted destinations. Broader telemetry or data-handling practices are not established by this page.

Freshness

The page was captured on 14 November 2026, and the captured text carries no publication or last-updated date. It includes notes on specific versions up to v2.1.310. Its publication date, update date and release cadence are unknown from this evidence. The live page may differ from this capture, so check the current page and the Claude Code version you run before relying on a specific setting name or version note.

What to do next

If you use Claude Code on macOS, Linux or WSL2, read the What the sandbox restricts and What runs outside the sandbox sections first, then run /sandbox and choose a mode. On Linux or WSL2, install bubblewrap and socat and restart Claude Code. Then ask Claude to run the two probe commands to confirm the boundary works.

Decide what to do about the unsandboxed retry. To turn it off, set allowUnsandboxedCommands to false. If you keep it, whether a retry prompts depends on your setup. Manual and acceptEdits modes show a Bash command (unsandboxed) prompt. A matching allow rule or bypassPermissions mode lets a retry run without a prompt, auto mode sends it to classifier review, and dontAsk mode refuses it. An ask rule for Bash(dangerouslyDisableSandbox:true) forces a prompt on retries, including in auto mode and bypassPermissions mode.

Add sandbox.credentials deny entries for the credential files and variables you care about, because none are protected by default. Keep allowedDomains narrow. Be careful with broad hosts, and with excludedCommands patterns that cover interpreters or scripts in your working directory.

For organisations: in managed settings, set enabled and failIfUnavailable to true and allowUnsandboxedCommands to false. Add approved excludedCommands and allowWrite entries centrally. Plan separately for Windows machines, where failIfUnavailable would stop Claude Code from starting. If hooks, MCP servers and file tools matter to you, consider the whole-process isolation options the page points to.

Check the Claude Code version you run against the version notes before relying on a feature. This page does not state the cost or plan terms for Claude Code, so confirm them elsewhere.

Evidence for this report

selected-page.txtselected · checked 2026-11-14