Claude Code’s sandbox puts an operating system boundary around the shell commands Claude runs: they can write only in the project and a temp directory, and every connection they open goes through a local proxy that compares the hostname with a list you keep. You turn it on with /sandbox. At its defaults, those same commands can still read ~/.ssh and ~/.aws/credentials, and the proxy never looks inside TLS.
Two things people often assume about the Claude Code sandbox are wrong according to Anthropic’s own sandboxing docs. It doesn’t hide your SSH keys until you list them, and turning it on doesn’t put Claude Code in --dangerously-skip-permissions, a permission mode that actually loosens the sandbox. We’d turn the sandbox on anyway. Most of what it leaves open is on the network, which is where Formal Endpoint sits, so the second half of this post is the rules we put there. A Claude Code devcontainer or a VM moves the boundary out to the whole process and leaves the same question about the traffic it lets through. Anthropic changes these settings often; what follows matches their page as of November 2026.
Turning on the Claude Code sandbox
Type /sandbox in a session. The panel has a Mode tab (auto-allow or regular permissions, below), an Overrides tab for whether a failed command may retry outside the sandbox, and a Config tab showing the resolved settings. macOS needs nothing else, because enforcement uses Seatbelt. Linux and WSL2 use bubblewrap for the filesystem and socat to relay traffic to the proxy, so install both first (sudo apt-get install bubblewrap socat on Debian and Ubuntu); while one is missing, the panel shows only a Dependencies tab. Native Windows gets no sandbox at all, and Anthropic’s advice is to run Claude Code inside WSL2.
Whatever mode you pick lands in .claude/settings.local.json, so it covers one project. Set sandbox.enabled to true in ~/.claude/settings.json for all of yours, or ship it in managed settings for a team.
One default deserves attention before anything else. When the sandbox can’t start, because the platform isn’t supported or bubblewrap isn’t installed, Claude Code carries on and runs commands unsandboxed, and the session looks the same as any other. Turn on sandbox.failIfUnavailable and Claude Code refuses to start in that case. On any machine where the sandbox is meant to be a control, that key belongs in managed settings next to sandbox.enabled.
To check it works, ask Claude to run touch ~/sandbox-probe and curl --noproxy '*' https://example.com. Typing them yourself at the ! prompt proves nothing, since those commands usually run outside the sandbox. Both should fail. The touch is refused (Operation not permitted from Seatbelt, Read-only file system from bubblewrap), and curl reports Could not resolve host, because a sandboxed command has no route that skips the proxy. If Claude offers to retry either one unsandboxed, decline.
Picking a sandbox mode: auto-allow or regular permissions
Both modes enforce the same filesystem and network limits. Auto-allow approves a sandboxed command without asking. Regular permissions keeps the usual prompt for every Bash command, sandboxed or not.
We’d run auto-allow. Prompting for each command feels safer than it is: when Drew Gregory on our team looked at allowlisting bash commands, approving go test, make or pnpm run turned out to mean approving anything, since those tools execute code the agent can edit. Anthropic’s docs add a less obvious problem with allow rules: they cover the retry too. With Bash(curl *) allowed, a curl the sandbox blocked can be rerun unsandboxed and nobody gets asked. Auto-allow still keeps the checks that hold up. A command a Bash deny rule matches is refused, deleting a critical path with rm or rmdir still prompts, and an ask rule such as Bash(git push *) still stops a sandboxed push for confirmation.
--dangerously-skip-permissions is a different thing from either mode. It puts Claude Code in bypassPermissions, where sandboxed commands may connect to hosts outside your allowed domains unless strictAllowlist is set, and unsandboxed retries run without asking. The dangerously-skip-permissions post covers when that trade is worth it.
What does the Claude Code sandbox leave open?
The Claude Code sandbox leaves reads, non-shell tools and three kinds of unsandboxed commands open. Anything running inside can read most of the machine, ~/.ssh and ~/.aws/credentials included, and inherit every environment variable Claude Code started with. Claude’s Read, Edit, Write, WebFetch and WebSearch tools, hooks, local MCP servers, mods and helpers like apiKeyHelper run outside it with your full access. Anthropic sums it up: “Sandboxing reduces risk but is not a complete isolation boundary.”
Reads are the easy fix, with sandbox.credentials entries. Nothing is hidden by default; the sandbox protects exactly the paths and variable names you put in that block. The tools outside the boundary answer to permission rules instead, so the Read tool ignores denyRead, and WebFetch goes wherever its own rules allow, whatever allowedDomains says. Claude Code hooks get their own post.
Shell commands leave the sandbox three ways. Anything matching excludedCommands runs with no filesystem limits and no proxy. Commands typed at the ! prompt mostly skip it. And after a failure, Claude may rerun a command with the dangerouslyDisableSandbox parameter, which strict sandbox mode (allowUnsandboxedCommands: false) tells Claude Code to ignore.
The exclusion list is the one that grows, because the sandbox breaks ordinary tools and the documented fix is often to exclude them. Anthropic calls docker incompatible with the sandbox. On macOS, git fetch, pull and push over SSH fail even to an allowed host. Most database drivers and plain ssh ignore the proxy variables, so they can’t connect from inside at all. Each workaround becomes an excludedCommands entry with your full access, and Anthropic’s warning about them is specific: exclude docker compose * and Claude can edit the compose file, then run it outside the sandbox.
Where the sandbox proxy and the devcontainer firewall stop
The sandbox’s network isolation starts from no route at all. On Linux a sandboxed process runs in its own network namespace; on macOS, Seatbelt blocks every connection except the one to the sandbox proxy. That proxy runs outside the sandbox and decides from the hostname. In Anthropic’s words, “By default the built-in proxy does not terminate or inspect TLS.” It knows a command connected to github.com. Whether that connection cloned your repository or pushed it to an account you’ve never seen, it can’t tell.
Anthropic is direct about the consequence. A broad entry like github.com can become a path for exfiltration, and because the allow decision rests on the hostname the client supplies, domain fronting can reach hosts that aren’t on the list. The experimental network.tlsTerminate setting does make the proxy terminate TLS, for one job: swapping masked credentials into requests. Anthropic says it adds no content filtering.
The firewall in Anthropic’s Claude Code devcontainer works a layer lower. Drew took it apart in our proxy post: init-firewall.sh resolves the allowed hostnames with dig when the container starts and opens those IP addresses in iptables. Another app behind the same load balancer, routed by SNI or Host header, is reachable through an allowed address, and port 22 is open to every address. As with the sandbox proxy, nothing in that path reads the request.
Built-in sandbox, devcontainer, Docker or a VM?
For Claude Code sandboxing on developer laptops, the built-in sandbox is the place to start. Move Claude Code into a container or VM when you also want its file tools, hooks and MCP servers inside a boundary, since the built-in one only wraps shell commands. A Claude Code devcontainer, a Docker container you build, Docker Sandboxes and a VM all isolate the whole process. None of them inspects the requests sent to the hosts you allow.
Anthropic’s devcontainer ships with the firewall above and mounts your workspace. A Claude Code Docker sandbox you build yourself starts with an open network plus whatever mounts and environment variables you pass in, so it’s as tight as its docker run line. Docker Sandboxes, driven by the sbx CLI, run the agent in a microVM with its own network policies. A full VM adds a separate kernel, which matters if container escapes are in your threat model, and changes nothing about what the agent can send to hosts it’s allowed to reach.
Inspecting what sandboxed commands send
Anthropic’s documented route to TLS inspection is a proxy you run yourself: point sandbox.network.httpProxyPort or socksProxyPort at its local port and install its CA inside the sandbox. The warning next to that setting matters. Once either port applies, Claude Code’s allowedDomains, deniedDomains, strictAllowlist, approval prompts and local-address check no longer cover that traffic, and your proxy has to do all of the filtering.
Formal Endpoint takes the other route. Transparent Mode, available on macOS and Linux, catches TCP connections in the OS networking stack; on a Mac, that’s a network extension. Claude Code gets no proxy settings, the sandbox keeps enforcing its own domain list, and the Endpoint sees what leaves the machine after that list has run. The proxy post showed one rule covering both the Claude Code CLI and the commands it runs in its sandbox.
Network rules choose which connections the Endpoint takes. Each one is a CEL expression with a condition per stage of the connection. The starter rule in the docs diverts traffic from known agents and every process they start, then intercepts their MCP and LLM calls:
{
"condition": {
"pre_tcp": process.is_agent || process.has_agent_ancestor,
"pre_tls": true,
"post_tls": technology in ["mcp", "llm"]
}
}
On macOS, the Endpoint recognizes Claude Code by its code signature (Team ID Q6L2SF6YDW, identifier com.anthropic.claude-code), and process.has_agent_ancestor extends the match to everything it starts: shell commands, hooks and local MCP servers, the last two being exactly what the sandbox never wrapped. pre_tcp selects the processes whose connections get diverted, and only runs on macOS. pre_tls decides whether the Endpoint terminates TLS, with certificates from the Formal local CA (how TLS inspection works). post_tls filters on the protocol Formal classifies once it can read the plaintext; http, aws, ssh and postgres are other values, so the same shape extends to ordinary API and database calls. On Linux, pre_tcp is ignored and the agent flags match the installed binary’s process name instead of a signature.
A connection that no rule selects passes through untouched, and traffic from a process that no pre_tcp condition matches never shows up in Logs.
Getting sandboxed clients to trust the Formal CA
Terminating TLS works only for clients that trust the Formal CA. formal ca trust installs it where browsers and Go programs look, in the OS trust store. Node.js and most Python HTTP libraries never consult that store; they bundle their own certificate list. For Claude Code, the Endpoint writes NODE_EXTRA_CA_CERTS, SSL_CERT_FILE and REQUESTS_CA_BUNDLE into ~/.claude/settings.json unless runtime_ca_env is none, and leaves alone any of the three you’ve already set. Anthropic documents that sandboxed commands inherit Claude Code’s environment, so those variables reach commands inside the sandbox as well. Setting transparent_proxy.runtime_ca_env = "all" adds the AWS CLI, pip, git, cargo and gRPC variables to your login session. A client that still rejects the certificate should come out of pre_tls; it then passes through uninspected instead of failing with CA errors. The runtime TLS trust table lists which variable each client reads.
Keeping API keys off the laptop
A deny entry for ~/.ssh hides a file. It does nothing for the key your code needs while it runs, the one exported in the shell you launched Claude Code from or sitting in the project’s .env.
Anthropic’s answer is mask mode under sandbox.credentials. Sandboxed commands see a per-session placeholder, and the sandbox proxy puts the real value into requests to the hosts you allow, which requires the experimental network.tlsTerminate. On macOS, a masked file can’t be read at all, the same effect as deny. Neither the command nor its output ever sees the secret. The laptop still stores it.
With credential injection, the key lives on a Formal Connector as a Native User. The Endpoint hands the requests a network rule selects to the Connector, tagged with the developer’s Formal identity, and the Connector adds the credential on the way upstream. The Stripe walkthrough does it with an Authorization: Bearer header: clients still call api.stripe.com, Stripe gets the real key, and the laptop never has it. Drew built the same setup for the Anthropic API key in the proxy post, launching Claude Code with ANTHROPIC_API_KEY=sk-ant-dummy while the Connector supplied the real one; a Rego policy on that traffic then surfaced in the session as API Error: 403.
Blocking agent pushes to an allowed github.com
Git over SSH is where the sandbox’s own workarounds open the widest hole. On macOS, git push to an SSH remote fails under the sandbox, allowed host or not, and Anthropic offers two fixes. Excluding git fetch *, git pull * and git push * takes those commands out of the sandbox, after which they “can reach any host, not only the ones in allowedDomains”. Switching the remote to HTTPS keeps git sandboxed, and then the proxy sees a push to github.com the way it sees a clone.
A control on one transport is bypassed by editing the remote URL, and GitHub takes pushes three ways: SSH, SSH on port 443 at ssh.github.com, and HTTPS. Our guide to blocking agent git pushes covers all three on macOS with one network rule:
{
"condition": {
"pre_tcp": process.has_agent_ancestor,
"pre_tls": hostname in ["github.com", "ssh.github.com"],
"post_tls": technology in ["http", "ssh"]
}
}
A Rego policy then blocks git-receive-pack, the server-side command behind every push. Over SSH it reads that command from the session; over HTTPS it matches the POST to <repository>/git-receive-pack. Clones and fetches use git-upload-pack and keep working. A push from the developer’s own terminal doesn’t match either, because that terminal isn’t an agent or a child of one. The repository match is a substring, so protecting acme/infrastructure also covers acme/infrastructure-docs. If a hard block is too strict, the guide also shows an mfa action: the push waits until the developer approves it on their own device. Create the policy in Dry-run, check what it matches, then set it to Active. The rule relies on code-signed process identity, which only macOS has. The Claude Code security page lists other documented policies.
Is the Claude Code sandbox enough?
For shell commands on a developer laptop, the built-in sandbox is worth turning on wherever your tools tolerate it, and it isn’t enough on its own. Its gaps (open reads, tools outside the boundary, an exclusion list that grows, a proxy that only sees hostnames) are where keys and data leave from. Closing them takes controls outside Claude Code that its own settings can’t switch off.
If you’re working out how to sandbox Claude Code for a team, these are the settings we’d start from:
sandbox.enabledandsandbox.failIfUnavailable, in managed settingsallowUnsandboxedCommands: false, so failed commands stay sandboxedsandbox.credentialsdeny entries for~/.ssh,~/.aws/credentialsand secret variables such asGITHUB_TOKEN- a short
allowedDomainslist withstrictAllowliston, so unknown hosts are refused instead of prompted excludedCommandsentries that each come with a written reason
Outside Claude Code, we’d put TLS-inspected egress on the flows that matter, keep API keys on a Connector, and block the actions that can’t be undone, starting with agent pushes to sensitive repositories. The sandbox decides where a command may connect. What it does once connected has to be checked somewhere the agent can’t reconfigure, and for us that’s the network path out of the machine.
Cursor’s security team drew the same line for its Cloud Agents: isolated environments with tightly restricted outbound connections, plus Formal policies on the data those agents reach. At Cursor, Formal covers 1,000+ resources across 10+ technologies and handles 40M+ logs and 600K+ sessions per week; the Cursor case study has the details.
“Without Formal, we couldn’t have agents with access to sensitive data. With Formal, because we are able to inspect all traffic and enforce controls, we are able to provide a safe environment for the agents to get the job done.”
— Travis McPeak, Head of Security @ Cursor
Frequently asked questions
Does the Claude Code sandbox work on Windows?
Only inside WSL2. Native Windows has no sandbox, so every command runs without one, and WSL1 doesn’t count either: /sandbox reports Sandboxing requires WSL2. Plan a rollout around it, because failIfUnavailable in managed settings makes Claude Code exit at startup on machines without a sandbox. Formal Endpoint’s Transparent Mode has a similar limit and runs on macOS and Linux.
What breaks when I turn the sandbox on?
A few tools, and Anthropic’s troubleshooting section names them. jest hangs because of watchman (run jest --no-watchman), Go CLIs such as gh, gcloud and terraform can fail TLS verification under Seatbelt, and open, osascript and browser sign-in flows fail with error -600 because Apple Events are blocked. When one more path or host is the problem, prefer allowWrite or allowedDomains to an exclusion.
Can Claude Code still read my credentials inside the sandbox?
Yes, until you add sandbox.credentials entries with "mode": "deny". Deny entries merge across settings scopes, and no scope can remove one another scope added, so a repository’s settings can’t undo yours. They only cover sandboxed commands; CLAUDE_CODE_SUBPROCESS_ENV_SCRUB strips credentials from every subprocess Claude Code starts.
Is a Claude Code devcontainer safer than the built-in sandbox?
For the rest of your laptop, yes, since the devcontainer puts the file tools and hooks behind the boundary too. Running the built-in sandbox inside it is awkward on Linux: without privileged namespaces it needs enableWeakerNestedSandbox, which Anthropic says “considerably weakens security”. We’d rely on the container for isolation and spend the effort on its network.
Can Claude Code escape its sandbox?
Mostly through settings someone widened. Anthropic lists the routes: allowing /var/run/docker.sock through allowUnixSockets hands over the host, write access to a directory on $PATH or to .bashrc lets code run later in another context, allowAppleEvents lets sandboxed commands launch other apps unsandboxed, and allowNestedUserNamespaces on Linux turns off a boundary. Review those keys as carefully as excludedCommands.
How do I sandbox Claude Code in CI or cloud agents?
No one is there to approve a prompt, so run it in a devcontainer, container or VM and set failIfUnavailable, so a runner without bubblewrap fails instead of running unsandboxed. Formal’s headless Linux package runs the Endpoint as a systemd user service on Debian and Ubuntu. On Cursor and Devin cloud agents, it signs in with the platform’s OIDC token, runs with enforce = true and fail = "closed", and a policy blocks pull request auto-merge. Our own setup is in Giving Cloud Agents Production Access with OIDC.
Formal Endpoint runs that egress layer on laptops, VMs and Kubernetes. If you’re rolling Claude Code out to a team and want to see these rules on your own agents, we can show you.