CLClaude Lessons Try the free lessons

Claude Lessons / Guides

Claude Code Sandboxing: Every Isolation Option Compared

There are two completely different questions people mean by "can I sandbox Claude Code," and most of the advice online answers only one of them. The first is how do I stop clicking Approve forty times an hour. The second is what actually contains this thing if I let it run while I sleep. They have different answers, and picking the wrong one is how people end up believing they are protected when they are not. Claude Code ships one isolation boundary of its own and supports five more around it, and each covers a different slice of what a session does. This guide compares all six by what they actually isolate, shows what still runs on your host under each, and gives you the one rule that decides which you need.

Illustration of choosing a boundary before letting work run on its own

The two questions, and why they diverge

Isolating Claude Code limits what a session can read, write and reach on the network. That matters most in two situations, and they are not the same situation.

Question one: fewer prompts during everyday work. You are at the keyboard. You just want the test suite to run without a permission dialog each time. A lightweight per-command boundary is exactly right here — if a command can only write inside your project and only reach domains you approved, auto-approving it is a reasonable trade.

Question two: something contains this while nobody is watching. You are launching with --dangerously-skip-permissions, or running an overnight migration, or wiring Claude into CI. Now the boundary is not a convenience — it is the only thing between a bad tool call and your laptop. A per-command boundary is not enough for this, for a reason covered in detail below: your hooks, your MCP servers and the file tools all run outside it.

Nearly every "how to sandbox Claude Code" article you will find answers question one, or jumps straight to Docker without saying which question Docker answers. The table below answers both.

All six options compared

The first two run on the host operating system with no containers involved. The rest use a container or a virtual machine.

Approach What is isolated Needs Docker Setup effort
Sandboxed Bash tool Bash, PowerShell and Monitor tool commands, and their child processes No Minimal on macOS; low on Linux and WSL2
Sandbox runtime The whole Claude Code process — file tools, MCP servers and hooks included No Low
Dev container Full development environment Yes Medium
Custom container Full development environment Yes Medium to high
Virtual machine Full operating system No High
Cloud session By default, shell commands and file edits, in a VM Anthropic hosts No None, but needs a Claude subscription

The single most important column is the second one. The sandboxed Bash tool restricts commands. The sandbox runtime and any container or VM put the whole Claude Code process inside the boundary, so the file tools, MCP servers and hooks are restricted too. That distinction decides everything else on this page.

Which one you need

You want toStart with
Cut permission prompts during everyday work on your own machine The sandboxed Bash tool in auto-allow mode, configured with /sandbox
Let Claude work unattended with --dangerously-skip-permissions or auto mode The preconfigured dev container, any container or VM, or the sandbox runtime
Isolate MCP servers and hooks as well as Bash, without Docker The sandbox runtime
Standardize a sandboxed environment across a team The preconfigured dev container, committed into your repository
Use Claude Code from a device with no local setup A cloud session
Require isolation for every developer in your organization Managed settings — and only the built-in Bash sandbox is truly enforceable
Work on a native Windows host A container or VM, or run the Bash sandbox inside WSL2

You can also layer them. Running the built-in Bash sandbox inside a container gives you OS-level command restrictions on top of the outer environment boundary, which is a sensible default for CI runners.

The rule: isolation vs. permission modes

This is the piece most guides skip, and it is the piece that determines whether your setup is real.

Permission modes decide whether a tool call runs and whether you are asked first. Isolation restricts what a command can access once it runs. They are orthogonal, and they compose: when a permission mode lets actions run without asking you, an isolation boundary limits what those actions can reach.

From there, one rule falls out of the documentation and it is worth memorising:

Always run --dangerously-skip-permissions sessions inside a container, a VM, or the sandbox runtime — something that contains the whole process, so file tools, MCP servers and hooks are inside the boundary too. With no prompts to catch mistakes, the isolation boundary you choose is what protects your system. The sandboxed Bash tool on its own constrains only shell commands, so it is explicitly not sufficient for fully unattended runs. On Linux and macOS, Claude Code refuses to start with that flag when running as root, so run the container, VM or runtime as a non-root user.

Auto mode sits differently. It replaces the prompt with a classifier that reviews each action. The classifier is a per-action control, not an isolation boundary, so an isolation boundary still adds defense in depth for unattended runs — but it is not required the way it is for --dangerously-skip-permissions. And note that even in auto mode, the actions no mode auto-approves still apply.

Option 1: the built-in sandboxed Bash tool

This is built into Claude Code. It uses operating system primitives — Seatbelt on macOS, bubblewrap on Linux and WSL2 — to restrict the filesystem and network access of the Bash, PowerShell and Monitor tool commands Claude runs, plus every process those commands start. Claude Code builds it on the open source @anthropic-ai/sandbox-runtime package.

It is off by default. Turn it on in one of two ways:

What a sandboxed command can reach

AccessDefaultChange it with
Writes The working directory, a per-user temp directory, and directories you added with --add-dir. Protected paths stay write-denied filesystem.allowWrite, filesystem.denyWrite
Reads Most of the machine, including credential files such as ~/.ssh and ~/.aws/credentials filesystem.denyRead, sandbox.credentials
Network No direct route out. Connections go through a proxy on your machine that checks each host against your allowed domains, which start empty network.allowedDomains, network.deniedDomains
Environment variables Inherited from Claude Code, including any secrets in its environment sandbox.credentials, CLAUDE_CODE_SUBPROCESS_ENV_SCRUB

Read that reads row again. The default sandbox stops a command from writing outside your project, but it does not stop it from reading your AWS credentials. If you care about that — and on a machine with real credentials you should — the credentials and denyRead settings are not optional extras, they are part of the baseline configuration.

Setup, by platform

Ripgrep ships with the native Claude Code binary. An optional seccomp filter adds Unix domain socket blocking; install it with npm install -g @anthropic-ai/sandbox-runtime if the /sandbox Dependencies tab reports it missing. The dependency check runs at startup, so restart Claude Code after installing packages or /sandbox will not see them.

On WSL2, check your version with wsl -l -v. A message reading Sandboxing needs WSL2 means your distribution is on WSL1 — upgrade it or run without sandboxing.

Prove it is actually on

The /sandbox panel saying "enabled" is not proof. Ask Claude to run each of these, because what you type yourself at the ! prompt usually runs outside the sandbox and therefore tests nothing:

CommandResult inside the sandbox
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, because the command has no route around the proxy

Where the setting lands

When you pick a mode in the panel, Claude Code saves it to your project's .claude/settings.local.json, which applies to that project only, and adds that file to your global gitignore. To sandbox every project, set sandbox.enabled in your user settings at ~/.claude/settings.json. To change the sandbox for a single session without writing to any settings file:

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

One warning worth internalising: by default, when the platform does not support the sandbox or the startup dependency check fails, Claude Code runs commands without sandboxing. It fails open. Set sandbox.failIfUnavailable to true to make it exit at startup instead. If you are treating the sandbox as a security gate rather than a convenience, that setting is mandatory.

What runs outside the Bash sandbox

This is the section to screenshot. The sandbox wraps shell commands. These run outside it, with your full access:

So: if your threat model includes "a prompt injection in a file Claude reads convinces it to exfiltrate something," the Bash sandbox alone does not close it, because WebFetch is outside the boundary. To put all of the above behind one boundary, run the Claude Code process inside the sandbox runtime, a container, or a VM.

Auto-allow vs. regular permissions

Both modes enforce identical filesystem and network restrictions. The only difference is whether sandboxed commands are auto-approved.

Auto-allow mode approves a command with no prompt when it runs inside the sandbox. It works independently of your permission mode, with narrow exceptions, which means sandboxed Bash commands that modify files run automatically even in Manual mode, where the file edit tools would prompt. People are often surprised by this. Even in auto-allow, these still apply:

A second surprise: commands where a prefix can change which program runs go through the normal permission flow anyway. FOO=bar npm test, make CC=clang and eval "ls" all prompt. The allow rules that stop the recurring prompt have to match the whole shape:

Regular permissions mode sends every Bash command through the normal permission flow even when sandboxed. More control, more approvals. Use it when the sandbox is a containment layer rather than a prompt-reduction tool.

The unsandboxed retry escape hatch

When a command fails inside the sandbox, Claude Code names the denied host or path in the result, Claude analyzes the failure, and it may retry the command with the dangerouslyDisableSandbox parameter. The retry runs outside the sandbox. Who approves it depends on your permission mode:

Permission modeWhat happens to the retry
bypassPermissionsRuns with no prompt
Manual and acceptEditsA prompt titled "Bash command (unsandboxed)"
Auto modeA separate classifier model evaluates it

Set sandbox.allowUnsandboxedCommands to false to remove the hatch entirely. Note that an allow rule matching a command also approves its unsandboxed retry, so broad allow rules quietly widen more than they look like they do.

Protected paths: the self-escalation block

Even inside directories a sandboxed command can write to, the sandbox denies writes to the files Claude Code loads configuration and code from. The reason is direct: a command that could edit those files could grant itself permissions, or add a hook or MCP server that Claude Code later runs outside the sandbox. Four groups are covered:

Adding an allowWrite entry or an Edit allow rule covering one of these paths does not lift the protection. Only filesystem.disabled does, and that turns off the rest of filesystem isolation with it. Run /sandbox and open the Config tab to see most of these resolved for your machine.

One caveat the docs flag explicitly: if you set allowNestedUserNamespaces to true on Linux or WSL2, do not rely on protected paths — code from a sandboxed command can end up running outside the sandbox.

How network isolation really works

A sandboxed command has no direct route to the network. On Linux and WSL2 it runs in a separate network namespace with no connection to your network; on macOS, Seatbelt blocks connections other than the one to the sandbox proxy. Claude Code runs that proxy on your machine, outside the sandbox, and points commands at it with HTTP_PROXY, HTTPS_PROXY, ALL_PROXY and related variables. The proxy checks each connection's hostname against your allowed and denied domains.

What reaches the outside world therefore depends entirely on whether a tool honours proxy variables:

Your allowed domains start empty. The first time a command needs a new domain you get a prompt. Choosing Yes allows the host for the rest of the session; choosing "Yes, and don't ask again" saves a WebFetch(domain:...) allow rule to your local settings so it persists. Pre-allow domains with network.allowedDomains to skip the prompt entirely, and set network.strictAllowlist to true — in user, managed or CLI --settings only — to deny anything outside the allowlist instead of prompting. That last one is what you want for unattended runs, where there is nobody to answer a prompt.

Option 2: the sandbox runtime

@anthropic-ai/sandbox-runtime wraps an entire process in the same Seatbelt or bubblewrap isolation the built-in Bash sandbox uses. Run Claude Code through it and the session's tools, hooks and MCP servers are constrained as well as shell commands — no Docker required. It is a beta research preview, and its configuration format may change as the package evolves.

It denies everything by default. Out of the box the runtime blocks network access and confines writes to a small set of built-in paths, so you configure it before launching Claude Code through it. Put your configuration in ~/.srt-settings.json, or a file you pass with --settings.

Allow write access to at least:

Allow the network domains the session needs:

On Linux and WSL2 the runtime applies write grants only to paths that already exist, so in a fresh environment create Claude Code's config paths first, then install and launch:

mkdir -p ~/.claude && { [ -f ~/.claude.json ] || echo '{}' > ~/.claude.json; }
npm install -g @anthropic-ai/sandbox-runtime
srt claude

Install the runtime under a prefix outside every path you allow writes to. The same srt command also works for sandboxing a standalone MCP server or any other helper process.

What the runtime blocks without being asked

Your write grants still cover other paths Claude Code loads configuration from, so deny those explicitly with denyWrite. A sandboxed session that can write them can persist hooks, permission rules or MCP servers that run unsandboxed the next time you launch. After an unattended run, review the paths you kept writable — and on Linux and WSL2, review anything the session created.

Options 3-5: dev containers, custom containers, VMs

Dev containers

A dev container runs Claude Code inside a Docker container that VS Code or a compatible editor manages, with your project mounted in. The claude-code repository publishes an example dev container with a default-deny iptables firewall. Copy it into your repository and adjust the firewall allowlist, the base image and the pinned Claude Code version. Because the firewall blocks unapproved egress, that configuration supports running with --dangerously-skip-permissions for unattended work.

This is also the best answer for standardizing across a team: commit it, and everyone gets the same boundary. Just be clear-eyed that it is a convention, not an enforcement boundary — see the org section below.

Custom containers

Any Docker or OCI image with your own network policies, mounted volumes and seccomp profiles. This is the common path for organizations that already have container infrastructure or CI runners, and managed sandbox services can host the container for you. The checklist is the same as for any container you operate: review what is mounted writable, what credentials and tokens are reachable inside it, and what the egress policy allows.

If you want the built-in Bash sandbox layered inside an unprivileged container, you will need enableWeakerNestedSandbox — which, as the name says, considerably weakens the inner boundary. Only use it when the outer container is doing the real isolation work.

Virtual machines

A dedicated VM gives the strongest separation: its own kernel, and in cloud or microVM deployments its own virtualized hardware. Cloud instances, local hypervisors, and microVMs such as Firecracker all qualify. Use this when your security policy requires kernel-level separation between the agent and the host, or when no host-level approach meets your compliance requirements. Docker Sandboxes provides a microVM with its own Docker daemon and workspace sync; it is a free standalone product and does not require Docker Desktop.

Option 6: cloud sessions

By default, a cloud session runs its shell commands and file edits in an isolated, Anthropic-managed virtual machine. A network proxy enforces a default allowlist, and a separate proxy holds your GitHub token outside the sandbox while issuing scoped credentials for repository access inside it — which is a meaningfully better token posture than mounting a PAT into a container you built yourself.

It requires a Claude subscription, and a connected GitHub account to work in a GitHub repository (unless you launch from the CLI with --cloud and let Claude Code bundle and upload your local repository). Sessions your organization routes to a self-hosted environment run on infrastructure you provision instead, where isolation, egress control and git credentials become your deployment's responsibility.

This is the zero-setup answer, and the right one when you are delegating from a device with no local development environment at all.

Enforcing isolation across an organization

Individual developers can opt into any approach on this page. What an organization can actually enforce is narrower than most rollout plans assume:

The managed settings baseline:

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

failIfUnavailable makes Claude Code refuse to start rather than fall back to unsandboxed execution when the platform is unsupported or a dependency is missing. allowUnsandboxedCommands: false makes it ignore the dangerouslyDisableSandbox escape hatch. Two additions worth making alongside them:

Know the merge semantics. When managed settings set a Boolean key such as enabled or failIfUnavailable, Claude Code uses the managed value and ignores anything a developer sets locally. But array keys such as allowRead merge across the scopes a session loads, so a developer can append entries that widen the policy unless a lock covers that key. Audit your array keys.

And the gap that remains under any configuration: a developer can still type a command at the ! shell-mode prompt and run it outside the sandbox, with the same access they already have in any terminal. The sandbox constrains what Claude runs, not what a person runs.

If your fleet includes native Windows hosts, failIfUnavailable will make Claude Code exit at startup on every one of them. Either deliver the configuration to macOS and Linux machines only — noting that server-managed settings follow the member, not the device — or move Windows users into WSL2 or a container first.

Security limitations nobody mentions

Sandbox isolation reduces the impact of a breach. It does not eliminate risk, and the documentation is unusually candid about where the edges are.

The failures you will actually hit

SymptomWhat is going on
/sandbox shows only a Dependencies tab The sandbox cannot start. Install what the tab lists, or add an AppArmor profile if it reports Ubuntu's AppArmor restriction. Restart Claude Code — the dependency check runs at startup
A database client or ssh cannot reach an allowed host The tool ignores proxy environment variables. Allowing the domain will not help
git over SSH fails, git over HTTPS works Same cause — SSH does not go through the proxy
A command fails to reach a server on localhost The sandbox has no route to your host's loopback. An allowed hostname that resolves to a loopback address is refused too
Operation not permitted for sandboxed commands inside a container Bubblewrap cannot start in an unprivileged container. This is where enableWeakerNestedSandbox comes in
A folder named objects or refs disappears after a command Expected: a newer top-level HEAD, objects or refs in your working directory is deleted after a sandboxed command unless it is a folder with contents. It is the bare-repo protection firing
git merge or git checkout fails with unable to unlink old The file is on the protected paths list
jest hangs, Go CLIs fail TLS on macOS, pbcopy does nothing Known sandbox interactions, each with its own documented fix. Reach for excludedCommands only after reading the specific one
/sandbox says settings cannot be changed here Managed settings have set the key. Booleans from managed settings win outright

Common mistakes

FAQ

Is Claude Code sandboxed by default?

No. The built-in sandbox is off until you turn it on with the /sandbox command in a session or by setting sandbox.enabled to true in a settings file. Nothing about installing Claude Code puts it in a sandbox, and no permission mode adds one. Permission modes decide whether a tool call runs at all; isolation decides what that call can reach once it is running. They are separate controls and you need to set the second one yourself.

What does the Claude Code sandbox NOT protect?

The built-in sandbox wraps shell commands only. Everything else in a session runs on your host with your full access: the Read, Edit, Write, WebFetch and WebSearch tools, command hooks, local MCP servers, plugin monitors, LSP servers, your status line command, apiKeyHelper, and mods. A denyRead entry does not stop the Read tool, and allowedDomains does not limit WebFetch — those follow permission rules instead. Commands you type yourself at the exclamation-mark shell prompt, commands matching excludedCommands, and unsandboxed retries also run outside it. To put all of that behind one boundary you have to isolate the whole Claude Code process with the sandbox runtime, a container, or a VM.

Can I run Claude Code with --dangerously-skip-permissions safely?

Only inside a boundary that contains the whole Claude Code process — a container, a virtual machine, or the sandbox runtime. With no prompts to catch a mistake, the isolation boundary is the only thing protecting your system, and the built-in Bash sandbox is not enough on its own because hooks, MCP servers and the file tools stay outside it. On Linux and macOS, Claude Code refuses to start with that flag when running as root, so run your container, VM or runtime as a non-root user. Auto mode is a different case: its classifier reviews each action, so isolation there is defense in depth rather than a hard requirement.

Does the Claude Code sandbox work on Windows?

Not on a native Windows host. The sandbox uses Seatbelt on macOS and bubblewrap on Linux, and there is no native Windows implementation. On Windows you run Claude Code inside WSL2, a container, or a VM. This matters for fleet rollouts: if you push sandbox.failIfUnavailable as a managed setting, Claude Code exits at startup on every native Windows machine, so either deliver that configuration to macOS and Linux machines only or move Windows users into WSL2 or a container first.

Why can't a sandboxed command reach my database or SSH host?

Because a sandboxed command has no direct network route at all. It reaches the outside world only through a proxy Claude Code runs on your machine, advertised through the HTTP_PROXY, HTTPS_PROXY and ALL_PROXY environment variables. Tools that read those variables — curl, npm, git over HTTPS — connect once their host is allowed. Tools that ignore them, including plain ssh and most database drivers, cannot connect even to an allowed host. Anything that is not TCP cannot leave the sandbox at all, so UDP, HTTP/3 over QUIC and ping also fail. Allowing the domain does not fix it; the tool has to speak to the proxy.

Is a sandboxed session safe from data exfiltration?

No, and the docs are explicit about it. Any approach that allows network egress can still leak data the agent can read. By default the built-in proxy does not terminate or inspect TLS, so it makes its allow decision from the client-supplied hostname — which means code inside the sandbox can potentially use domain fronting to reach hosts outside your allowlist. Allowing a broad domain such as github.com widens that path considerably. If your threat model needs a real guarantee, run a custom proxy that terminates TLS and inspects traffic, and install its CA certificate inside the sandbox. Isolation also changes nothing about what is sent to the model: your prompts and the files Claude reads go to your provider with or without a sandbox.

What is the difference between the sandboxed Bash tool and the sandbox runtime?

They use the same underlying isolation — Seatbelt on macOS, bubblewrap on Linux — but wrap different things. The built-in sandboxed Bash tool wraps each shell command Claude runs, so Claude Code itself stays on your host. The sandbox runtime, the npm package anthropic-ai/sandbox-runtime, wraps the entire Claude Code process, so the file tools, hooks and MCP servers are inside the boundary too. Neither needs Docker. The trade is setup: the Bash sandbox is a /sandbox command away, while the runtime needs a settings file that grants your project directory, Claude Code's config paths and its temp directory before anything works. The runtime is a beta research preview and its configuration format may still change.

Can my organization force every developer to run Claude Code sandboxed?

Only for the built-in Bash sandbox, which is the single approach Claude Code enforces itself. Deliver the sandbox keys through managed settings, either as an MDM-managed file or through server-managed settings on claude.ai. Setting enabled, failIfUnavailable and allowUnsandboxedCommands false gives you a sandbox that refuses to start rather than silently falling back, and that ignores the unsandboxed retry escape hatch. Dev containers are a convention rather than an enforcement boundary, because Claude Code does not require a container — if developers must not run outside one, enforce that with device management or software allowlisting. One gap remains either way: a developer can still type a command at the shell prompt and run it with the access they already have in any terminal.

Isolation is the floor, not the skill

A sandbox limits the blast radius of a bad decision. It does not make the decisions better. The lessons drill the habits that keep an agent from needing the blast radius in the first place: scoping the task, inspecting before acting, and verifying what came back.

Start the free lessons