# Claude Code Sandbox Options, from /sandbox to a VM

> Every way to sandbox Claude Code: the built-in /sandbox and its settings, Docker, a dev container or a microVM, and what each one blocks and lets through.

- URL: https://flockvm.com/learn/claude-code-sandbox
- Last updated: 2026-11-10

Claude Code can be sandboxed at four depths: the built-in `/sandbox`, which fences shell commands only; a container or dev container, which fences the whole Claude Code process but shares your kernel; Docker Sandboxes, a microVM on your machine; and a VM on another machine. Pick by the risk you care about, not by the name "sandbox": the built-in one is for fewer prompts on your own code, and Anthropic says it "is not sufficient for fully unattended runs".

| If what worries you is… | Use at least | Why |
|---|---|---|
| Approving every `npm test` by hand | `/sandbox` in auto-allow mode | Sandboxed commands run without a prompt; writes stay in the project |
| An `rm -rf` that leaves the project | `/sandbox` (for Bash), or any container | Sandboxed commands write only to the project, a temp dir and directories you add |
| `--dangerously-skip-permissions` or auto mode, unattended | A dev container, the sandbox runtime, Docker Sandboxes or a VM | File tools, MCP servers and hooks must be inside the boundary too |
| Secrets leaving over the network | A strict egress allowlist, wherever you run | Every layer that allows egress "can still leak data the agent can read" |
| A kernel or container-runtime exploit | A microVM or VM: Docker Sandboxes, a cloud session, a remote VM | Only those give the agent its own kernel |
| An untrusted repository | A dedicated VM, or a cloud session | Anthropic's own pick for that row |

Everything below was checked against Anthropic's and Docker's documentation on 5 November 2026.

## What does Claude Code's /sandbox isolate?

`/sandbox` turns on the sandboxed Bash tool, "a boundary that the operating system enforces around the shell commands Claude runs on your machine". It is **off by default**. It covers Bash, PowerShell and Monitor commands and the processes they start, and nothing else: "Claude's file tools, MCP servers, and hooks run outside it."

It uses Seatbelt on macOS and `bubblewrap` plus `socat` on Linux and WSL2. On native Windows, commands run unsandboxed; run Claude Code inside WSL2 to get it. Under the hood is Anthropic's open-source `@anthropic-ai/sandbox-runtime` package.

Its default boundary, from the [sandboxing docs](https://code.claude.com/docs/en/sandboxing):

| | Default |
|---|---|
| Writes | The working directory, a per-user temp directory and directories you added. "Protected paths stay write-denied" |
| Reads | "Most of the machine, including credential files such as `~/.ssh` and `~/.aws/credentials`" |
| Network | No direct route out: a local proxy checks each host against `allowedDomains`, which starts empty |
| Environment | Inherited from Claude Code, "including any secrets in its environment" |

The protected paths are the files Claude Code loads code and settings from: in the project and above it, the `.claude` settings and its `skills`, `agents`, `commands` and `hooks` directories and `.mcp.json`; in the project, shell startup files such as `.bashrc`, `.gitconfig`, `.vscode`, `.idea`, and `hooks` and `config` inside `.git`; and most of `~/.claude`, including the `.credentials.json` store.

What runs outside it, with your full access: Read, Edit, Write, WebFetch and WebSearch (they follow permission rules instead: "`allowedDomains` doesn't limit WebFetch"), command hooks, local MCP servers, plugin monitors, LSP servers, the status line command and `apiKeyHelper`. The proxy checks hostnames and "does not terminate or inspect TLS traffic", and UDP, QUIC and `ping` can't leave the sandbox.

### Claude Code sandbox mode: auto-allow or regular permissions

The `/sandbox` panel has three tabs, Mode, Overrides and Config, and two modes:

- **Auto-allow**: a command that runs inside the sandbox is approved with no prompt. This is the mode that cuts prompts.
- **Regular permissions**: every Bash command goes through the normal permission flow, sandboxed or not.

The sandbox mode is separate from the permission mode. When a sandboxed command connects to a host outside your allowlist, the permission mode decides: you get a prompt in Manual and `acceptEdits` modes, auto mode refuses it unless the classifier approved that host for the command, `dontAsk` refuses it, and **`bypassPermissions` lets it through without a prompt**, unless `sandbox.network.strictAllowlist` is on.

### Claude Code sandbox settings

The same boundary can live in `~/.claude/settings.json`, so it doesn't depend on someone typing `/sandbox`:

```json
{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "filesystem": {
      "denyRead": ["~/.ssh", "~/.aws"]
    },
    "network": {
      "allowedDomains": ["github.com", "*.npmjs.org"],
      "strictAllowlist": true
    }
  }
}
```

| Key | What it does |
|---|---|
| `sandbox.enabled` | Turns the sandbox on (off by default) |
| `sandbox.failIfUnavailable` | Exits at startup instead of running unsandboxed when bubblewrap or the platform check fails |
| `sandbox.allowUnsandboxedCommands` | `false` ignores the `dangerouslyDisableSandbox` retry: "strict sandbox mode" |
| `sandbox.autoAllowBashIfSandboxed` | Auto-approves sandboxed commands (default `true`) |
| `sandbox.filesystem.allowWrite` / `denyWrite` | Extra writable paths / paths never writable |
| `sandbox.filesystem.denyRead` / `allowRead` | Paths sandboxed commands can't read / exceptions inside a denied area |
| `sandbox.network.allowedDomains` / `deniedDomains` | Hosts sandboxed commands may reach / hosts always refused |
| `sandbox.network.strictAllowlist` | Refuses unlisted hosts in every permission mode instead of prompting. User, managed or `--settings` only: a repository's `.claude/settings.json` can't turn it on or off |
| `sandbox.credentials.files[]` / `envVars[]` | Per file or variable, `deny` it or `mask` it (masking needs the experimental `network.tlsTerminate`) |
| `sandbox.excludedCommands` | Command patterns that run outside the sandbox, such as `"docker compose *"` |

Two traps. `denyRead` stops sandboxed commands, not the Read tool: add a permission deny rule for that. And if you set `allowNestedUserNamespaces` to `true`, Anthropic warns, you "turn off a security boundary". The full list is on Anthropic's [sandboxing page](https://code.claude.com/docs/en/sandboxing).

## The sandbox runtime: the whole process, without Docker

The [sandbox runtime](https://github.com/anthropics/sandbox-runtime) (`srt`, Apache 2.0, a "research preview") wraps any process in the same Seatbelt or bubblewrap boundary. `srt claude` puts the whole Claude Code process inside, so file tools, hooks and MCP servers are fenced too. By default it denies network access and confines writes to a few runtime paths; you allow your project, `~/.claude`, `~/.claude.json`, the temp directory, `api.anthropic.com`, and `claude.ai` plus `platform.claude.com` if you sign in with a subscription. It blocks writes to `.git/hooks`, `.mcp.json`, `.claude/commands`, `.claude/agents` and shell startup files at the project root on its own.

It is Anthropic's lightest option for unattended runs, with two limits: reads are allowed everywhere by default, and it shares your kernel. On Linux, its deny list is built once at launch, so a repository the session clones later isn't covered.

## Claude Code in Docker, and Docker Sandboxes

**A plain container** (`docker run` with the project mounted) puts the whole Claude Code process in its own filesystem and network namespace. Three things to get right:

- **Never mount the Docker socket.** Docker's daemon "requires `root` privileges", and Docker's own advice is that "only trusted users should be allowed to control your Docker daemon". An agent with the socket can start a container that mounts your whole disk.
- **Run as a non-root user.** Claude Code refuses `--dangerously-skip-permissions` as root or under `sudo` outside a recognized sandbox.
- **Egress is open by default.** "Containers have networking enabled by default, and they can make outgoing connections": add a firewall or a proxy.

`/sandbox` and Docker don't mix well: "`docker` is incompatible with the sandbox", so Docker commands have to go in `excludedCommands`, and running bubblewrap inside an unprivileged container needs `enableWeakerNestedSandbox`. And a container "shares the kernel of the machine it runs on", in Docker's words.

**Docker Sandboxes** is the other Docker product: a microVM per agent, with "a kernel of its own" and a private Docker daemon, on your machine or on Docker's cloud. The CLI and local sandboxes are "free to use, including for commercial work", and Anthropic notes it doesn't require Docker Desktop. One command:

```bash
sbx run claude ~/my-project
```

That starts `claude --dangerously-skip-permissions` by default. Sign in with `/login` inside the session, or store an API key with `sbx secret set anthropic`: a host-side proxy adds it to requests, and "the raw credential values never enter the VM". Outbound TCP is "blocked unless an explicit rule allows the destination", outbound UDP is off, and DNS goes through a resolver "which enforces network policy". The caveats: "the default allowed domains include broad wildcards" (`sbx policy ls` shows them), the default direct mount is read-write so the agent "edits your working tree in place" (clone mode avoids that), and local stdio MCP servers run on the host. If one of these rules it out, [Docker Sandboxes alternatives](/compare/docker-sandboxes-alternatives) sorts the other options by the reason you're leaving.

## Claude Code sandbox vs dev container

The built-in sandbox fences commands on your host; a dev container moves the whole session into a Docker container that your editor (VS Code, Codespaces, JetBrains, Cursor) attaches to. Anthropic's [reference dev container](https://code.claude.com/docs/en/devcontainer) is three files in the `anthropics/claude-code` repository:

- `devcontainer.json`: runs as the non-root `node` user, bind-mounts your project at `/workspace`, keeps `~/.claude` in a named volume, adds the `NET_ADMIN` and `NET_RAW` capabilities, and runs the firewall at each start;
- `Dockerfile`: the base image, tools and the Claude Code install;
- `init-firewall.sh`: default policy DROP on input, forward and output.

Read the firewall's allowlist before you trust it. It allows `registry.npmjs.org`, `api.anthropic.com`, `sentry.io`, `statsig.com`, three VS Code domains, and every IP range GitHub publishes for its web, API and git services. It also accepts outbound DNS (UDP 53) and SSH (TCP 22) to any host, and the host's /24. So a `git push` to any repository on GitHub goes out, and so does data encoded in DNS lookups.

Anthropic's own warning: with `--dangerously-skip-permissions`, dev containers "do not prevent a malicious project from exfiltrating anything accessible inside the container, including the Claude Code credentials stored in `~/.claude`". The project is bind-mounted, so a deletion or a planted `.git/hooks` file inside it lands on your disk. Use it for trusted repositories, and mount no host secrets.

| | `/sandbox` | Reference dev container |
|---|---|---|
| What's inside the boundary | Shell commands | The whole Claude Code process, MCP servers and hooks included |
| Needs Docker | No | Yes |
| Your home directory | Readable by commands, not writable | Not there unless you mount it |
| Network | Proxy, empty allowlist; bypass mode lets unlisted hosts through without `strictAllowlist` | iptables allowlist; DNS and SSH open to any host |
| Kernel | Yours | Yours (shared with the container) |
| Good for | Fewer prompts on your own code | A team-wide environment, unattended runs on trusted repos |

## A remote microVM

A virtual machine is the strongest option in Anthropic's list, "with its own kernel and, in cloud or microVM deployments, its own virtualized hardware". On another machine, it also takes your laptop out of reach: the agent can wreck the VM, not your home directory, and you delete the VM afterwards.

Two kinds:

- **Anthropic's cloud sessions** run in an Anthropic-managed VM. "A network proxy enforces a default allowlist, and a separate proxy holds your GitHub token outside the sandbox." They need a Claude subscription. [Claude Code in the cloud](/learn/claude-code-in-the-cloud) covers when they fit.
- **A VM of your own**: a cloud instance, a VPS, or a Firecracker microVM service. You choose the image, the size and what's installed, and egress filtering is yours to set up. [Claude Code on a remote server](/learn/claude-code-remote-server) walks through the setup over SSH.

flockvm is one of the second kind, and the product this site is about. Each VM is a Firecracker microVM with its own kernel, on one host in France. The default Agent image has Claude Code preinstalled and logs you in as the non-root `user`, so `--dangerously-skip-permissions` works. You sign in with `/login` inside the session in the VM, or give the VM your organization's Anthropic API key through an environment. What it doesn't do yet: outbound IPv4 is open (only private ranges, cloud metadata, other VMs, the host and SMTP port 25 are blocked), and there is no egress allowlist and no secrets proxy. So a flockvm VM protects your machine and gives each agent its own kernel; it doesn't stop an agent from sending out what it can read inside the VM.

## What does each Claude Code sandbox block?

Default settings, from each vendor's documentation on 5 November 2026. This describes design, not an attack we ran.

| Risk | `/sandbox` | Sandbox runtime (`srt claude`) | Docker container | Reference dev container | Docker Sandboxes | Remote microVM (flockvm today) |
|---|---|---|---|---|---|---|
| Deleting files outside the project | Blocked for shell commands; the Edit and Write tools follow permission rules | Blocked: writes only where you allow | Blocked unless mounted | Blocked unless mounted | Blocked: nothing outside the workspace is shared | Not reachable: your machine isn't there |
| Deleting or poisoning the project | Writable; protected paths (`.git/hooks`, `.claude/`, `.mcp.json`) are not, for commands | Writable; `.git/hooks`, `.mcp.json` and shell startup files denied | Writable through the mount | Writable, and it's your host's folder | Writable in place by default; clone mode keeps a private clone | Writable, but it's the VM's copy |
| Reading secrets | Commands read most of the machine, `~/.ssh` included, unless `denyRead` or `sandbox.credentials` | Reads allowed everywhere by default | What's in the container | What's in the container, `~/.claude` included | The VM's files; keys stored with `sbx secret` stay on the host | What's in the VM: your laptop's files aren't |
| Network egress | Allowlist via proxy; open in bypass mode without `strictAllowlist`; WebFetch not covered | Denied by default; allowlist | Open by default | Allowlist, plus DNS and SSH to any host | Deny by default, broad default wildcards | Open IPv4, except private ranges, metadata, other VMs, the host, port 25 |
| Kernel or runtime exploits | Same kernel as your machine | Same kernel | Same kernel as the host | Same kernel as the host | Own kernel per sandbox | Own kernel per VM, on another machine |

What the table says:

- **Nothing on this list stops a prompt injection.** It only limits what a followed injection can reach.
- **Egress is the weak spot everywhere.** Anthropic: "Any approach that allows network egress can still leak data the agent can read." The fix is a short hostname allowlist, wherever you run.
- **Only microVMs and VMs change the kernel row.** In the first four columns, a kernel bug, or a container breakout, can reach your host. [MicroVM vs container](/learn/microvm-vs-container) explains why.

For the same layers tested against seven concrete attacks (DNS leaks, a `git push` with a planted token, `.git/hooks`), see [running Claude Code with --dangerously-skip-permissions safely](/learn/dangerously-skip-permissions-safely).

## What is the best Claude Code sandbox?

There isn't one best; there is one per situation:

- **Your own code, at your desk, fewer prompts**: `/sandbox` in auto-allow mode, with `failIfUnavailable`, `allowUnsandboxedCommands: false` and `strictAllowlist` in user settings.
- **Unattended on your laptop, no Docker**: `srt claude`, with a written allowlist.
- **A whole team, one setup**: Anthropic's dev container, with the firewall's allowlist trimmed.
- **Unattended on your laptop, with host-held API keys**: Docker Sandboxes.
- **Untrusted code, or agents that should run without your laptop**: a VM elsewhere, a cloud session or your own.

You can stack them: `/sandbox` inside a container or VM adds per-command limits on top of the outer boundary.

## When flockvm is the wrong pick

- **You need an egress allowlist or a secrets proxy today.** flockvm has neither yet; Docker Sandboxes and Anthropic's cloud sessions do.
- **You run one agent on your own code.** `/sandbox` or a dev container costs nothing and needs no remote machine.
- **You need many VMs at once.** The host in France runs 15 small VMs (2 vCPU / 4 GiB) at once, across all customers, 2 during the trial; it is the one region today, and others are planned.
- **You'd rather Anthropic run the VM.** That's a cloud session, which needs a Claude subscription.

If you want a throwaway Firecracker VM per agent, with Claude Code already installed, flockvm bills per second ($0.016 an hour for a small VM on 5 November 2026) against an $18 monthly plan that comes back as VM time. The [7-day free trial](/pricing) needs a card and charges nothing for 7 days. [Claude Code in a VM](/integrations/claude-code) shows the setup.

## FAQ

### Is the Claude Code sandbox on by default?

No. Run `/sandbox` in a session or set `sandbox.enabled: true` in a settings file. Without `sandbox.failIfUnavailable: true`, a missing dependency means commands run unsandboxed.

### Does /sandbox work with --dangerously-skip-permissions?

It stays active, but in bypass mode a host outside your allowlist is "allowed without a prompt" unless `sandbox.network.strictAllowlist` is on. File tools, MCP servers and hooks stay outside it either way. Anthropic's rule for that flag: "Always run `--dangerously-skip-permissions` sessions inside a container, a VM, or the sandbox runtime."

### Does the Claude Code sandbox work on Windows?

Not natively: on native Windows, commands run unsandboxed. Run Claude Code inside WSL2, or in a container or VM.

### Is a dev container a sandbox?

It isolates the whole session from your host's files, but not your project folder (bind-mounted) and not your kernel. With the reference firewall it also limits egress, with DNS, SSH and all of GitHub left open.

### Does a sandbox send less of my code to Anthropic?

No. "Isolation also does not change what is sent to the model": the files Claude reads go to the API with or without a sandbox.

### Can Claude Code use Docker inside the sandbox?

Not inside `/sandbox`: Docker commands have to be excluded and then run unsandboxed. Docker Sandboxes and VMs, flockvm's included, have their own Docker daemon, so `docker build` and `docker compose` work inside the boundary.

## Sources

- [Claude Code docs: Configure the sandboxed Bash tool (/sandbox, settings, limitations)](https://code.claude.com/docs/en/sandboxing) (accessed 2026-11-05)
- [Claude Code docs: Choose a sandbox environment](https://code.claude.com/docs/en/sandbox-environments) (accessed 2026-11-05)
- [Claude Code docs: Development containers](https://code.claude.com/docs/en/devcontainer) (accessed 2026-11-05)
- [Claude Code docs: Choose a permission mode](https://code.claude.com/docs/en/permission-modes) (accessed 2026-11-05)
- [anthropics/claude-code: .devcontainer/devcontainer.json (reference container)](https://github.com/anthropics/claude-code/blob/main/.devcontainer/devcontainer.json) (accessed 2026-11-05)
- [anthropics/claude-code: .devcontainer/init-firewall.sh (reference firewall)](https://github.com/anthropics/claude-code/blob/main/.devcontainer/init-firewall.sh) (accessed 2026-11-05)
- [anthropics/sandbox-runtime (srt): README](https://github.com/anthropics/sandbox-runtime) (accessed 2026-11-05)
- [Docker docs: Docker Sandboxes](https://docs.docker.com/ai/sandboxes/) (accessed 2026-11-05)
- [Docker docs: Claude Code in Docker Sandboxes](https://docs.docker.com/ai/sandboxes/agents/claude-code/) (accessed 2026-11-05)
- [Docker docs: Docker Sandboxes security model](https://docs.docker.com/ai/sandboxes/security/) (accessed 2026-11-05)
- [Docker docs: Docker Sandboxes default security posture](https://docs.docker.com/ai/sandboxes/security/defaults/) (accessed 2026-11-05)
- [Docker: Docker Sandboxes vs containers](https://www.docker.com/products/docker-sandboxes/vs-containers/) (accessed 2026-11-05)
- [Docker docs: Docker Engine security](https://docs.docker.com/engine/security/) (accessed 2026-11-05)
- [Docker docs: Networking overview](https://docs.docker.com/engine/network/) (accessed 2026-11-05)
