← Blog
Claude Code, Codex and coding agentsGuide

Claude Code sandbox: built-in isolation, Docker and cloud

The Claude Code sandbox is a boundary your operating system enforces around the shell commands Claude runs: it limits which files they can write and which hosts they can reach. Turn it on by typing /sandbox in a session and choosing a mode, or set sandbox.enabled to true in ~/.claude/settings.json. It works on macOS, Linux and WSL2; on native Windows, Claude Code runs commands unsandboxed.

The built-in sandbox covers shell commands only. For a wider boundary, run Claude Code in a dev container, a microVM or a separate cloud machine. This guide covers each one.

What does the built-in Claude Code sandbox protect?

Claude Code wraps Bash, PowerShell and Monitor commands, and every process they start, in an OS-level sandbox: Seatbelt on macOS, bubblewrap on Linux and WSL2. By default, a sandboxed command can reach the following, per the Claude Code sandboxing documentation:

AccessDefaultSetting that changes it
WritesThe working directory, a per-user temp directory and directories added with --add-dir. Files Claude Code loads settings and code from, such as .claude settings and .mcp.json, stay write-protectedsandbox.filesystem.allowWrite, sandbox.filesystem.denyWrite
ReadsMost of the machine, including ~/.ssh and ~/.aws/credentialssandbox.filesystem.denyRead, sandbox.credentials
NetworkNo direct route out. A proxy on your machine checks each host against your allowed domains, which start emptysandbox.network.allowedDomains, sandbox.network.deniedDomains
Environment variablesInherited from Claude Code, secrets includedsandbox.credentials

Claude's file and web tools (Read, Edit, Write, WebFetch, WebSearch), hooks, local MCP servers, plugin monitors, LSP servers and mods run outside this boundary. So do commands you type at the ! prompt in most sessions, commands listed in excludedCommands and commands Claude retries outside the sandbox after a failure. To contain the whole agent process, use one of the other setups below. A remote MCP service keeps whatever permissions you gave it.

SetupWhat it containsWhat you still need to control
Built-in Claude Code sandboxShell commands and their child processesFile tools, hooks, MCP servers, readable paths and allowed domains
Sandbox runtime (srt claude)The whole Claude Code process, including file tools, hooks and MCP serversIts settings file, write paths and network allowlist. It is a beta research preview
Docker dev containerProcesses and files inside the containerHost mounts, Docker socket access, privileges and network policy
Cloud workspaceAgent processes on a separate machine or runtimeUploaded data, credentials, network access and the workspace's actual isolation boundary

Enable Claude Code sandbox mode

On macOS, Claude Code uses the built-in Seatbelt framework, so you install nothing. On Linux or WSL2, install bubblewrap and socat first. For a Debian or Ubuntu system:

sudo apt-get install bubblewrap socat

On Fedora, run sudo dnf install bubblewrap socat. Restart Claude Code afterwards, because it checks dependencies at startup.

The built-in sandbox does not run on native Windows. Run Claude Code inside a WSL2 distribution and install the packages there as you would on Linux. WSL1 is not enough; check your version with wsl -l -v in PowerShell. If WSL2 is not an option, Anthropic suggests a container or VM instead, and Docker Sandboxes (below) runs on Windows 11. We did not test Windows or WSL isolation, so run the boundary check below before you rely on it.

Start Claude Code in your project and enter:

/sandbox

The panel has three tabs. Mode sets how sandboxed commands are approved, Overrides sets whether a blocked command may retry outside the sandbox, and Config shows the resolved settings. On Linux, a Dependencies tab appears when something is missing; if it is the only tab, the sandbox cannot start yet.

Auto-allow mode runs sandboxed commands without a prompt. Regular permissions mode keeps the usual approval flow while the sandbox stays on. Both apply the same file and network limits. In auto-allow mode, deny rules and ask rules for a specific command, such as Bash(git push *), still apply.

Claude Code saves your choice to .claude/settings.local.json, so it covers the current project. To turn the sandbox on for every project, add this to ~/.claude/settings.json:

{
  "sandbox": {
    "enabled": true,
    "autoAllowBashIfSandboxed": true
  }
}

Leave out autoAllowBashIfSandboxed to keep regular permissions mode. In November 2026, Claude Code changed that key's default from true to false, so a sandbox turned on from a settings file no longer approves sandboxed commands on its own unless you set the key. See the settings reference.

For a session that must keep shell commands inside the sandbox, start Claude Code with:

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

allowUnsandboxedCommands: false turns on what the Overrides tab calls strict sandbox mode: Claude can no longer retry a blocked command outside the sandbox. Passed through --settings, it also makes Claude Code ignore repository settings that would loosen the sandbox, such as a project's excludedCommands. failIfUnavailable: true makes startup fail if sandbox support is missing; without it, Claude Code runs commands unsandboxed. Review any excluded commands in your user settings as well.

File reads stay broad by default. To keep sandboxed commands away from credential files and secret variables, list them under sandbox.credentials:

{
  "sandbox": {
    "enabled": true,
    "credentials": {
      "files": [
        { "path": "~/.aws/credentials", "mode": "deny" },
        { "path": "~/.ssh", "mode": "deny" }
      ],
      "envVars": [
        { "name": "GITHUB_TOKEN", "mode": "deny" }
      ]
    }
  }
}

There is no built-in deny list, so the sandbox blocks only what you list.

Check the boundary before a long run

Ask Claude to execute these commands through its shell tool:

touch ~/sandbox-probe
curl --noproxy '*' https://example.com

Run the test from a project folder below your home directory. The first command writes outside the project, so it should fail: Anthropic's docs give Operation not permitted on macOS and Read-only file system on Linux and WSL2. The second tries to bypass the network proxy and should fail with Could not resolve host. A permitted request through the proxy can still succeed.

If Claude offers to retry a failed check outside the sandbox, decline. Have Claude execute the checks: a command you type at the ! prompt or in another terminal runs outside the sandbox, so it does not test the boundary. If touch succeeds, delete ~/sandbox-probe and run /sandbox to see whether the sandbox is on.

What happens when a command needs the network

Your allowed domains start empty. When a sandboxed command first connects to a new host, your permission mode decides:

  • Manual and acceptEdits modes: you get a prompt. "Yes" allows the host for the session, and "Yes, and don't ask again" saves the rule.
  • Auto mode: Claude must name the host on the command, and the classifier reviews both. Other hosts are refused.
  • dontAsk mode: the connection is refused.
  • bypassPermissions mode: the connection goes through without a prompt.

To refuse every host outside your list in all modes, set sandbox.network.strictAllowlist to true in your user settings or --settings, and list hosts in sandbox.network.allowedDomains. Tools that ignore proxy variables, such as plain ssh and most database drivers, cannot connect even to an allowed host, and UDP traffic cannot leave the sandbox.

Sandbox mode, auto mode and skipping permissions

Permission modes decide whether a tool call runs and whether Claude asks first. The sandbox controls what a shell command can reach once it runs. /sandbox is not a permission mode.

Claude Code's auto mode uses a separate classifier model to review actions before they run. With Claude Code 2.1.283 or later, interactive terminal sessions start in auto mode when it is available for your account and model. The sandbox's auto-allow mode is different: it skips prompts because the sandbox contains the command. The two work independently and can be combined. See permission modes and our auto mode guide.

--dangerously-skip-permissions bypasses permission prompts and protected-path checks. It does not create a container, restrict file access or set a network policy. Deny rules and a few checks, such as the prompt for rm on critical paths, still apply. In this mode, an unsandboxed retry runs without a prompt, and a sandboxed command can reach hosts outside your allowed domains. Set allowUnsandboxedCommands: false and strictAllowlist: true to stop both. Anthropic says to run such sessions inside a container, a VM or the sandbox runtime, because the shell sandbox does not cover file tools, MCP servers or hooks. Our guide to dangerously-skip-permissions covers that workflow, and our headless guide covers claude -p runs.

Run Claude Code in Docker

A dev container gives the team the same starting environment and keeps the agent's processes inside a container. Install Docker and use an editor with Dev Containers support. Add this file at .devcontainer/devcontainer.json in your project:

{
  "image": "mcr.microsoft.com/devcontainers/base:ubuntu",
  "remoteUser": "vscode",
  "features": {
    "ghcr.io/devcontainers/features/node:1": {
      "version": "22"
    },
    "ghcr.io/anthropics/devcontainer-features/claude-code:1.0": {}
  }
}

Open the project in the container, let it build, then run claude in its terminal and sign in. This configuration installs Claude Code and Node.js 22. Add any other runtimes and dependencies your project needs. The feature's :1.0 tag pins its install script, not the Claude Code release: it installs the latest Claude Code, which then updates itself inside the container. To pin a version, Anthropic suggests installing it with npm in your Dockerfile and setting DISABLE_AUTOUPDATER to 1.

We tested a clean build of this exact configuration. Claude then fixed an intentionally failing Node.js test, and a separate node --test run passed. Including the Node.js feature matters: our first clean build with only the Claude Code feature failed while installing Node.js and npm. Anthropic's dev container guide now gives the same fix for the Failed to install Node.js and npm error.

Keep remoteUser as a non-root account such as vscode: Claude Code refuses --dangerously-skip-permissions as root on Linux and macOS.

Check the mounts before handing the agent work. A writable project mount lets it change the files on your host. Avoid mounting your home directory, production credentials or the host's Docker socket. This minimal config does not add a network allowlist; Anthropic's reference container adds one with its init-firewall.sh script. See Docker's security documentation for the controls your setup needs.

Docker containers and Docker Sandboxes differ

Docker also offers a product called Docker Sandboxes. Its sbx CLI runs each agent in a microVM with its own Docker daemon, on your machine or in Docker's cloud, and it does not need Docker Desktop. Local sandboxes are free; Docker bills its cloud sandboxes by usage. To start Claude Code on a project, Docker's Claude Code page gives:

sbx run claude ~/my-project

By default, that starts claude --dangerously-skip-permissions inside the microVM. The sbx CLI runs on macOS 14 or later on Apple silicon, Windows 11 on 64-bit Intel or AMD, and Ubuntu 24.04 or later, so it is one way to isolate Claude Code on native Windows.

An ordinary dev container does not gain these properties just because it uses Docker. Read the Docker Sandboxes architecture and security model before treating the two setups as equivalent. We did not test Docker Sandboxes for this guide; our Docker Sandboxes guide covers setup, network policy and prices.

When a cloud sandbox helps

A remote workspace helps when the task must keep running after your laptop disconnects, when agents need separate working trees, or when your application creates a workspace for each user. You can copy in a repository, run the agent, inspect its changes and retrieve the files you want to keep.

Anthropic offers one option itself. claude --cloud "your task" starts a cloud session in an Anthropic-managed VM, with network access limited by default. It needs a Pro, Max, Ultra or Team plan, or an eligible Enterprise seat, and counts toward your plan's usage limits with no separate VM charge. It clones your GitHub remote, or uploads your local repository as a bundle when it cannot. See Use Claude Code in the cloud.

Lizard Sandboxes runs each sandbox as a Firecracker microVM with its own kernel. You choose the size, lifetime and model credential, and you can run many sandboxes at once; see how to run coding agents in parallel.

A separate machine keeps the job away from files you have not shared from your laptop. Credentials and files you do put inside that machine remain available to code running there. Set their scope to match the task.

Run Claude Code in Lizard Sandboxes

Install Lizard CLI, sign in and choose a project. You need an Anthropic API key or a Claude subscription token for the model calls.

To register an Anthropic API key, run:

lizard agents add anthropic

For a Claude subscription, create a token and register it with Lizard CLI:

claude setup-token
lizard agents add claude

Paste the credential at the prompt. Keep it out of your repository and command history. Credentials belong to the project, so every member of that project can use them. The commands below assume registration has succeeded; our live test used an existing Claude subscription token.

Create the workspace

Replace YOUR_PROJECT_ID with your project ID:

lizard sandbox create \
  --project YOUR_PROJECT_ID \
  --template claude \
  --size small \
  --timeout 3600000 \
  --json

Set SB to the sandbox ID in that response:

SB=YOUR_SANDBOX_ID

The claude template comes with Node.js 22, a pinned Claude Code release and git. Without --size, a sandbox is Medium (4 vCPU, 8 GB). During the trial, sandboxes are Small, Mini or Nano, run in US regions and live at most one hour, with up to 1 Small, 2 Mini and 2 Nano running at a time.

The timeout here gives the workspace a one-hour lifetime. The default is five minutes. When the lifetime ends, Lizard deletes the sandbox and its files, even mid-task, and running commands does not extend it. Extend a running sandbox with lizard sandbox timeout "$SB" 3600000, and save your work before it expires. See the CLI reference for lifecycle commands.

Copy a committed repository without a GitHub token

From the local repository, create a Git bundle and upload it:

BUNDLE_DIR=$(mktemp -d)
git bundle create "$BUNDLE_DIR/app.bundle" HEAD
lizard sandbox files put \
  "$SB" "$BUNDLE_DIR/app.bundle" /workspace/app.bundle
lizard sandbox exec "$SB" -- \
  git clone /workspace/app.bundle /workspace/app

The bundle includes committed history reachable from HEAD. It excludes uncommitted and untracked files, but any secrets committed in that history still travel with it. Review the repository before transferring it. Cloning this bundle can leave the checkout at a detached HEAD; you can still inspect the agent's edits and export changed files.

If the code is on GitHub, you have connected GitHub to Lizard and Lizard's GitHub App is installed on the repository's owner, lizard sandbox create --repo owner/name clones it into /workspace/<name> at creation instead, with write access to that repository only.

Give Claude a small task

lizard sandbox prompt "$SB" \
  --agent claude \
  --cwd /workspace/app \
  "Run the tests. Fix one failing test with the smallest reasonable change. Report what changed and which tests passed."

Keep --agent claude: without it, the CLI sends the prompt to Codex, the default agent. Pass --cwd on follow-up prompts too. Each turn runs claude -p with --dangerously-skip-permissions as root inside the sandbox, so the task runs without prompts. The workspace boundary and the credentials you provide therefore need to match the task. Code inside it can read the model credential available to the process.

In our test, a Python function subtracted two numbers when its test expected their sum. Claude changed that function, and an independent test run passed afterward.

Review and retrieve the result

lizard sandbox exec "$SB" -- \
  git -C /workspace/app status --short
lizard sandbox exec "$SB" -- \
  git -C /workspace/app diff
lizard sandbox files get \
  "$SB" /workspace/app/path/to/changed-file ./changed-file.review

Replace path/to/changed-file with the file you want to download. Run the project's tests yourself before merging the changes. We checked the remote diff, reran the test and downloaded the corrected file; its contents matched the remote result.

When you have saved the result, pause the workspace:

lizard sandbox pause "$SB"

Wait until its status is paused. A successful pause stops compute charges; the paused sandbox's disk then bills at $0.14 per GB-month of used space until you resume or delete it. Export work before removing a sandbox, and use Persistent Volumes when data must survive the sandbox's deletion. They also bill at $0.14 per GB-month.

What does the cloud workspace cost?

Lizard's published sandbox rates on 2 December 2026:

SizeCPU and memoryCompute per hour
Nano0.5 vCPU, 1 GB$0.00405
Mini1 vCPU, 2 GB$0.0081
Small2 vCPU, 4 GB$0.0162
Medium4 vCPU, 8 GB$0.0324
Large8 vCPU, 16 GB$0.0648
Big (paid plans only)16 vCPU, 32 GB$0.1296

Lizard bills each size per second while it runs, idle time included. The claude template runs on every size. At the Small rate, 100 sandbox-hours consume $1.62 of compute usage; at the Nano rate, $0.405. The rate includes CPU, memory and up to 2 TB of sandbox egress per account over a rolling 30 days. Paused disk and Persistent Volumes bill separately.

Lizard Pro costs $19 a month, taxes included, and includes $19 of usage. Usage above that amount is pay as you go. Pro runs up to 40 vCPU of sandboxes at once, such as 20 Small. New accounts get a seven-day trial with $5 of usage; a card is required. Claude subscription or Anthropic API charges are separate from Lizard charges. Check the current pricing before sizing a job.

Common setup problems

ProblemWhat to check
Native sandbox cannot start on LinuxInstall bubblewrap and socat, then restart Claude Code. The /sandbox Dependencies tab lists what is missing.
Ubuntu's AppArmor restriction stops bubblewrapAdd an AppArmor profile for /usr/bin/bwrap, or run sudo sysctl -w kernel.apparmor_restrict_unprivileged_userns=0, which lifts the restriction for every program until you reboot.
Sandboxing needs WSL2 on WindowsThe distribution runs WSL1. Upgrade it to WSL2.
A needed domain is blockedAdd only the required host to sandbox.network.allowedDomains and retry through the proxy.
docker commands fail in the sandboxDocker does not work inside it. Exclude a narrow pattern such as docker compose * with sandbox.excludedCommands; matching commands then run with your full access.
bubblewrap fails inside a containerIn an unprivileged container, set enableWeakerNestedSandbox to true only when the container already provides the boundary you need. It weakens the sandbox.
/sandbox says settings can't be changed here--settings or managed settings set the key. Run /status and read the Setting sources line.
Host files change during a Docker runCheck writable mounts. A mounted repository shares those edits with the host.
The wrong agent starts in LizardPass --agent claude explicitly.
A cloud job ends before it finishesSet a suitable lifetime or extend it with lizard sandbox timeout. Commands do not reset the lifetime.

What we tested

On 18 October 2026, we ran Claude Code 2.1.286 on macOS and in a fresh Small Firecracker sandbox through Lizard CLI 4.0.58. The macOS check allowed a workspace write and blocked both a write outside the project and a direct network request that bypassed the proxy.

The cloud test covered Git bundle upload, cloning, Claude fixing a failing Python test, an independent test rerun, diff review, file download and pause. We confirmed the sandbox reached paused.

The Docker test used Docker Engine 28.1.1 on ARM64, Dev Containers CLI 0.89.0, Node.js 22.23.3 and Claude Code 2.1.302. The corrected config built from a clean container, and Claude fixed a failing Node.js test that passed on a separate rerun. We also verified the Linux package installation command.

Authentication used an existing Claude subscription token. We did not repeat initial OAuth enrollment or test native Windows/WSL isolation or Docker Sandboxes. These checks cover the commands and outcomes described here; they are not a security audit.

On 2 December 2026, we re-checked the facts in this guide against Anthropic's Claude Code docs and changelog, Docker's documentation and Lizard's pricing and CLI docs, without rerunning the hands-on tests. Both Claude Code versions above predate the November 2026 change to the autoAllowBashIfSandboxed default.

Which setup should you choose?

Start with the built-in Claude Code sandbox for local shell tasks where you can define the needed paths and domains. On Windows, run it inside WSL2 or use a container or VM. Use a dev container when your team needs a shared development setup. Choose a cloud workspace when tasks need remote compute or separate environments for concurrent agents.

For a first Lizard run, copy a small repository, ask Claude to fix one failing test, review the diff and pause the workspace. The Claude Code guide has the current setup steps.

FAQ

Can I sandbox MCP servers and hooks too, without Docker?

Yes, with Anthropic's sandbox runtime, a beta research preview. It wraps the whole Claude Code process in the same Seatbelt or bubblewrap boundary. Install it with npm install -g @anthropic-ai/sandbox-runtime, put your write paths and allowed domains in ~/.srt-settings.json, then start Claude Code with srt claude. The runtime blocks network access by default, so allow api.anthropic.com and, for subscription sign-in, claude.ai and platform.claude.com. Allow writes to your project, ~/.claude, ~/.claude.json and Claude Code's temp directory. See Choose a sandbox environment.

Does the Claude Agent SDK support the sandbox?

Yes. The TypeScript Agent SDK has a sandbox option that takes the same keys as the settings file, such as enabled, autoAllowBashIfSandboxed and network. One default differs: in the SDK, failIfUnavailable is true, so a query fails when the sandbox cannot start. See the SDK reference. The option still covers shell commands only; our Agent SDK sandbox guide covers giving each task its own workspace.

Related guides: Codex sandbox: modes, --yolo, Docker and cloud · AI sandbox: isolation, code execution, and costs · Docker Sandboxes: coding agents in microVMs, local or cloud

Build with AI. Ship with Lizard

You don't need a platform team to go live. Your whole cloud, one CLI command away.

Start 7-day trial
Services
—
Add-ons
—
Deployments
—
Sandbox starts
—

We use cookies for essential site functionality and analytics. See our Cookie Policy.