Table of Contents
- What a Claude Code sandbox actually means
- Why sandbox Claude Code at all
- The built-in /sandbox: what it protects, and what it does not
- sandbox-runtime: the whole process, no Docker
- Docker and devcontainers: the standard answer for YOLO mode
- Hosted sandboxes that run Claude Code, with real prices
- Which Claude Code sandbox should you use?
- Running a Claude Code sandbox 24/7
- FAQ
- Is Claude Code sandboxed by default?
- Is it safe to run claude --dangerously-skip-permissions?
- Does the built-in sandbox stop prompt injection?
- Can Claude disable its own sandbox?
- What does a Claude Code sandbox cost?
/sandbox feature wraps only shell commands and is off by default, while a real container, VM, or hosted sandbox wraps the whole agent, which is what Anthropic itself says you need before running --dangerously-skip-permissions. This guide compares every tier with October 2026 prices, from free local tools to always-on sandboxes like Agent37 from $4.76 per month.What a Claude Code sandbox actually means
/sandbox command or "sandbox": {"enabled": true} in settings. It limits where commands write and which domains they reach, and because the operating system enforces the limits, Claude Code can run sandboxed commands without asking you to approve each one. Anthropic measured an 84 percent drop in permission prompts in internal usage.--dangerously-skip-permissions sessions inside a container, a VM, or the sandbox runtime, so that file tools, MCP servers, and hooks are also inside the boundary."Why sandbox Claude Code at all
~/.bashrc. And in November 2025, Anthropic disclosed that a state-sponsored group had manipulated Claude Code into attempting infiltration of roughly thirty organizations, with the AI performing 80 to 90 percent of the campaign autonomously.bypassPermissions "offers no protection against prompt injection or unintended actions." Isolation is the control that still works when the model is wrong or deceived. If you want the architecture background on how strong each isolation tier is, we compared gVisor, microVMs, and full VMs in depth.The built-in /sandbox: what it protects, and what it does not
- Writes are limited to your working directory and a per-user temp directory. Claude Code's own config surfaces (settings files,
.git/hooks,.mcp.json, shell startup files) are always write-denied, with no way to exempt them.
- Network starts at zero. Commands reach the internet only through a local proxy that checks every host against your allowlist.
- Sandboxed commands run without permission prompts, which is the whole point: flow instead of click fatigue.
- It only wraps shell commands. "The sandbox covers shell commands only. Claude's file tools, MCP servers, and hooks run outside it."
- It is off by default. You must run
/sandboxor setsandbox.enabledyourself.
- Reads are open by default. Commands can read "most of the machine, including credential files such as
~/.ssh", and "there is no built-in credential deny list." You have to configuredenyReador thesandbox.credentialsblock yourself.
- There is an escape hatch. When a command fails inside the sandbox, Claude may retry it with a parameter literally named
dangerouslyDisableSandbox. Who approves that retry depends on your permission mode. Strict sandbox mode ("allowUnsandboxedCommands": false) removes the hatch entirely, and since v2.1.285 an admin-enforced strict sandbox cannot be loosened by repository settings.
- Missing dependencies fail open. If bubblewrap or socat is absent, Claude Code runs commands unsandboxed unless you set
failIfUnavailable: true.
- Native Windows is not supported. On Windows, commands run unsandboxed unless you work inside WSL2.
sandbox-runtime: the whole process, no Docker
@anthropic-ai/sandbox-runtime (srt), the Apache-2.0 project Anthropic open-sourced in October 2025 and builds the embedded sandbox on. Around 5,500 GitHub stars as of October 2026, labeled a beta research preview.npx @anthropic-ai/sandbox-runtime claude and the same Seatbelt or bubblewrap isolation wraps the entire Claude Code process, including file tools, MCP servers, and hooks. Defaults are stricter than the embedded version: writes denied everywhere until allowed, all network denied until allowed. You grant your project directory, ~/.claude, temp, and api.anthropic.com, and you have a credible lightweight boundary for unattended runs on a trusted machine, with no image builds and no daemon.Docker and devcontainers: the standard answer for YOLO mode
--dangerously-skip-permissions, and the standard way to run it safely is a container you can afford to lose.devcontainer.json, a Dockerfile, and init-firewall.sh, a default-deny iptables egress firewall. The docs are explicit that this combination "supports running Claude Code with --dangerously-skip-permissions for unattended work." There is also an official Dev Container Feature (ghcr.io/anthropics/devcontainer-features/claude-code) for adding Claude Code to any existing devcontainer. Community projects fill the gaps for plain Docker: claudebox (about 1,200 stars) and coi (about 750) are the active ones people actually use.- Run as a non-root user. Claude Code refuses to start with
--dangerously-skip-permissionsas root on Linux and macOS.
- Auth without a browser. Pass
ANTHROPIC_API_KEYas an env var for API billing, or mint a one-year subscription token on your own machine withclaude setup-tokenand pass it asCLAUDE_CODE_OAUTH_TOKEN(works on Pro, Max, Team, and Enterprise plans, model requests only). To make interactive logins survive rebuilds, mount a volume at~/.claudeand pointCLAUDE_CONFIG_DIRat it; the account record lives in~/.claude.json, which otherwise sits outside the volume.
- Do not mount host secrets. Anthropic's warning is blunt: with permissions skipped, "dev containers do not prevent a malicious project from exfiltrating anything accessible inside the container, including the Claude Code credentials stored in
~/.claude." Keep~/.sshand cloud credentials out, and use repo-scoped, short-lived tokens.
Hosted sandboxes that run Claude Code, with real prices
Provider | Official Claude Code guide | Pricing basis (Oct 2026) | Session limits |
E2B | Yes, prebuilt claude template | ~$0.17/hr at 2 vCPU/4 GB, per-second metering | 1 hr continuous on the free tier, 24 hr on Pro ($150/mo) |
Daytona | Yes, CLI and SDK guides | ~$0.17/hr, per-second metering | No duration cap |
Modal | Yes, official sandbox example | ~$0.24/hr for the same shape | 24 hr max per sandbox (default 5 min; snapshot to go longer) |
Fly.io Sprites | Yes, Claude Code preinstalled | $0.0385/CPU-hr + $0.021875/GB-hr of use | No cap, auto-suspends when idle |
Cloudflare Sandboxes | Yes, official docs tutorial | Active-CPU metering on Workers Paid ($5/mo base) | No duration cap |
Vercel Sandbox | Yes, via the Claude Agent SDK | $0.128/hr active CPU + provisioned memory | 45 min on Hobby, longer on paid plans |
Agent37 | Yes, agent37-claude-code template | $4.76/mo for 2 vCPU/4 GB/4 GB disk, 730 hours | Persistent, no cap |
Which Claude Code sandbox should you use?
Option | Isolation strength | Covers file tools/MCP? | Platforms | Cost | Best for |
Built-in /sandbox | OS-level, Bash commands only | No | macOS, Linux, WSL2 | Free | Interactive daily coding with fewer prompts |
sandbox-runtime (srt) | OS-level, whole process | Yes | macOS, Linux (Windows alpha) | Free | Unattended runs on trusted repos, no Docker |
Devcontainer / Docker | Container + egress firewall | Yes | Anywhere Docker runs | Free (your hardware) | YOLO mode on repos you mostly trust |
Local VM / microVM | Hardware virtualization | Yes | Needs virtualization support | Free to cheap | Untrusted code on your own machine |
Claude cloud sessions | Anthropic-managed VM | Yes | Browser, mobile, CLI | Included in Pro/Max/Team limits | Delegating tasks without infrastructure |
Ephemeral cloud sandbox (E2B, Daytona, Modal...) | microVM or gVisor | Yes | Any | ~$0.06 to $0.24/hr | CI jobs, bursts, programmatic fleets |
Persistent cloud sandbox (Agent37) | gVisor, or full KVM VM | Yes | Any | $4.76/mo always-on | Agents that keep state and run 24/7 |
Running a Claude Code sandbox 24/7
claude -p demo, then the sandbox dies with your terminal. Real agent workflows are not one-shot. A code-review bot, an overnight refactoring queue, a cron job that triages issues at 6 a.m.: these need a sandbox that is still there when your laptop is not.agent37-claude-code template:- Isolation by default. Every standard instance runs under gVisor ("Isolation enforced by the kernel", with a hard per-instance disk quota), the same runtime Modal uses for sandboxing. If you need a stronger boundary, a
vminstance is "a full Linux virtual machine with its own kernel and KVM hardware virtualization" at 2.5x the compute rate, from $11.36 per month.
- Honest cost. The standard 2 vCPU / 4 GB / 4 GB disk shape is $4.76 per 730-hour month, metered by the minute with no plan fee. Turn on auto-sleep and a mostly idle agent costs a fraction of that: awake an hour a day works out to about $0.54 per month, because sleeping instances pay for disk alone. Agent37's own pricing page compares 31 providers at published rates and backs the "95% lower cost than most sandbox providers" headline with a refund-the-difference guarantee.
- Your Anthropic account, three ways. Open the instance terminal and run
claude auth login, or pass aCLAUDE_CODE_OAUTH_TOKENminted withclaude setup-token, or setANTHROPIC_API_KEYon the create call. Agent37 never supplies or bills Claude model usage; the honest math is sandbox from $4.76 plus whatever you already pay Anthropic. There is also a bring-your-own-model path viaANTHROPIC_BASE_URLfor compatible endpoints.
- State survives. Files, sessions, and logins persist until you delete the instance. That is the practical difference between a sandbox priced for ephemeral bursts and one priced to be your agent's permanent computer.
FAQ
Is Claude Code sandboxed by default?
/sandbox or sandbox.enabled in settings. What Claude Code has by default is the permission system; since v2.1.283 sessions start in auto mode, where a classifier model reviews actions and you are prompted only for what it escalates. On native Windows, commands run unsandboxed entirely; use WSL2.Is it safe to run claude --dangerously-skip-permissions?
Does the built-in sandbox stop prompt injection?
Can Claude disable its own sandbox?
dangerouslyDisableSandbox parameter, gated by your permission mode. Lock it down with strict sandbox mode ("allowUnsandboxedCommands": false), which makes unsandboxed retries impossible, and since v2.1.285 an enforced strict sandbox cannot be loosened by project settings.What does a Claude Code sandbox cost?
/sandbox today for the prompt relief, keep YOLO mode inside a boundary you can afford to lose, and when your agent earns a permanent job, give it a permanent, isolated computer. Spin one up on Agent37 Cloud with the $5 starter credit and the first month of the sandbox is effectively free.