What does Claude Code's Bash sandbox leave uncovered, and when should the whole process run in a dev container or VM instead?
answer
- shell commands only
- file tools follow permission rules
- hooks and MCP servers run with full access
- sandbox runtime wraps the whole process
- unattended or untrusted means an outer boundary
basics
~20 sThe Bash sandbox wraps only shell commands. Read, Edit, WebFetch, hooks, local MCP servers and helper commands run outside it. For unattended runs or untrusted code, put the whole Claude Code process in the sandbox runtime, a container or a VM.
solid answer
~50 sThe sandbox covers Bash, PowerShell and Monitor commands and their children. The built-in file and web tools (Read, Edit, Write, WebFetch, WebSearch) follow permission rules instead, so a sandbox `denyRead` doesn't stop the Read tool and `allowedDomains` doesn't limit WebFetch. Command hooks, local MCP servers, LSP servers, the status line command and `apiKeyHelper` run with your full access, and so do commands you type at `!`, excluded commands and approved unsandboxed retries. That is enough to cut prompts on your own machine, but not for a run nobody watches. Then the whole process goes inside a boundary: the `@anthropic-ai/sandbox-runtime` package (a beta research preview, no Docker needed), a dev container such as the reference one with its default-deny firewall, a custom container, or a VM for untrusted code. Even then, a writable mounted workspace can still be changed, and allowed egress can still leak data.
go deeper
Recall that the sandbox wraps only shell commands, and that file tools, hooks and MCP servers run outside it.
Explain which layer governs each tool: permission rules for Read, Edit and WebFetch, and the sandbox for shell commands and their children.
Match the boundary to the risk: Bash sandbox for interactive work, sandbox runtime or a container for unattended runs, a VM for untrusted code.
Recognize what isolation can't fix (writable mounts, allowed egress, data sent to the provider), and that dev containers need enforcement from outside Claude Code.
## The Bash sandbox has a narrow scope by design The built-in sandbox is an OS boundary around **shell commands**: the Bash, PowerShell and Monitor commands Claude runs and the processes they start. Everything else in a session runs in, or next to, the Claude Code process with your normal access. **Outside the sandbox:** - **Built-in file and web tools**: Read, Edit, Write, WebFetch and WebSearch run inside the Claude Code process and follow permission rules. A sandbox `filesystem.denyRead` entry does not stop the Read tool, and `network.allowedDomains` does not limit WebFetch. - **Other processes Claude Code starts**: command hooks, local MCP servers, plugin monitors, LSP servers, the status line command and `apiKeyHelper` all run with your full access. - **Commands you type** at the `!` shell-mode prompt, in most sessions. - **Excluded commands** matching `sandbox.excludedCommands`, and **unsandboxed retries** Claude makes after a failure, once approved. Subagents run in the same process and share the parent's sandbox configuration, so their Bash commands are sandboxed when the parent's are. ## Why that matters Because the sandbox covers only shell commands, it is **not enough for fully unattended runs**. When nobody reviews tool calls, whether under `--dangerously-skip-permissions` or auto mode, a hook, an MCP server or a file edit can still reach anything you can. The docs say to run a `--dangerously-skip-permissions` session inside a container, a VM or the sandbox runtime, as a non-root user. On Linux and macOS, Claude Code refuses that flag when it runs as root. Which mode to choose for such a run is a separate decision; the point here is the boundary around it. ## The heavier options | Approach | What is isolated | Needs Docker | Typical use | | --- | --- | --- | --- | | Bash sandbox | Shell commands and their children | No | Fewer prompts on your own machine | | Sandbox runtime | The whole Claude Code process | No | Hooks and MCP servers inside the boundary, without Docker | | Dev container | A full development environment | Yes | A standard isolated setup shared by a team | | Custom container | A full development environment | Yes | Existing container infrastructure and CI runners | | Virtual machine | A whole operating system with its own kernel | No | Untrusted repositories, kernel-level separation | - **Sandbox runtime**: `npx @anthropic-ai/sandbox-runtime claude` wraps the whole process in the same Seatbelt or bubblewrap isolation, configured in `~/.srt-settings.json`. It is a **beta research preview**. You must allow writes to the project, `~/.claude`, `~/.claude.json` and the runtime temp directory, and allow your API endpoint. It blocks network access by default, and if the settings file is missing it still starts with that locked-down default, so a clean start doesn't prove your settings loaded. - **Dev container**: Claude Code installs through the Claude Code Dev Container Feature. The reference container in the `anthropics/claude-code` repository adds an `init-firewall.sh` default-deny egress firewall, with the `NET_ADMIN` and `NET_RAW` capabilities that firewall needs, and runs Claude Code as a non-root user. Blocking unapproved egress and confining commands to the container are why the docs consider it suitable for unattended work. - **Custom container**: you can still layer the Bash sandbox inside it for per-command limits. An unprivileged container needs `sandbox.enableWeakerNestedSandbox`, because bubblewrap cannot mount a fresh `/proc` there. Use it only when the outer container already gives you the isolation you need. - **Virtual machine**: the strongest separation, and the recommended choice for evaluating untrusted code. ## What no boundary fixes 1. **The mounted workspace is writable**, so a bypassed session can still change your code, and the changes appear on the host. 2. **Allowed egress can leak** anything the session can read, including Claude Code's own credentials in `~/.claude`. Don't mount host secrets such as `~/.ssh` into a container; prefer short-lived, repository-scoped tokens. 3. **Isolation doesn't change what is sent to the model.** Prompts and the files Claude reads still go to the API provider. 4. **A committed dev container is a convention, not enforcement.** Claude Code does not require it, so making developers use it takes device management or software allowlisting. ## Choosing - On your own machine, to cut prompts: the Bash sandbox in auto-allow mode. - For hooks and MCP servers inside the boundary without Docker: the sandbox runtime. - For a team standard or unattended work: the reference dev container, adjusted, with its firewall. - For an untrusted repository: a dedicated VM.
- You run Claude Code with the Bash sandbox in a CI container, and every sandboxed command fails with `Can't mount proc on /newroot/proc: Operation not permitted`. What do you change?In an unprivileged container, bubblewrap can't mount a fresh `/proc`. Set `sandbox.enableWeakerNestedSandbox` to `true` so the inner sandbox bind-mounts the container's existing `/proc`. That exposes process information a fresh mount would hide, so use it only when the container itself is the isolation boundary you rely on.
- Your sandbox has `denyRead` on `~/.aws`, yet Claude read a file there. How?Most likely it used the Read tool. The built-in file tools run inside the Claude Code process and follow permission rules, not sandbox settings, so `denyRead` only binds shell commands. Add a `Read` deny rule for the path, which the sandbox also merges into its configuration, or run the whole process under the sandbox runtime or in a container that doesn't mount the directory.
- Your team commits the reference dev container. Does that stop someone running Claude Code on the bare host?No. Claude Code does not require a container, so a committed dev container standardizes the environment but enforces nothing. To prevent installs outside it, use your organization's device management or software allowlisting. The only isolation Claude Code enforces itself is the Bash sandbox, through managed settings.
- With the sandbox on, hooks and MCP servers are sandboxed too.
- A sandbox denyRead entry also stops the Read tool.
- Sandbox allowedDomains also limits what WebFetch can fetch.
- The Bash sandbox alone makes --dangerously-skip-permissions safe.
- Running inside a container keeps file contents from reaching the model provider.
- Committing a dev container forces every developer to use it.