Claude sandbox: Claude Code sandbox setup and VM costs

Choose the right Claude sandbox boundary, configure strict Claude Code settings, and budget hosted compute and retained disk separately from models.

•

Published on

•

Claude sandbox: Claude Code sandbox setup and VM costs
Do not index
A Claude sandbox can restrict individual shell commands or contain the whole agent, depending on where you place the boundary. The built-in Claude Code sandbox is enabled with /sandbox; a container, sandbox runtime, or VM can contain the whole process. Agent37 offers standard gVisor sandboxes and full VMs for that outer environment, with different capabilities and prices.
Start with the access your job needs. A repository cleanup, a Docker build, and a test against a private database require different permissions. Choosing the runtime first helps you avoid paying for unnecessary infrastructure or weakening restrictions just to make a build pass.
This guide was checked against official documentation and public prices on November 1, 2026.

What the Claude Code sandbox protects

The built-in sandbox is off by default. On macOS it uses Seatbelt; Linux and WSL2 use bubblewrap. Native Windows does not support this sandbox. Its scope covers Bash, PowerShell, and Monitor tool commands and their subprocesses. File tools and hooks need separate controls.
Writes are normally limited to the working directory, a per-user temporary directory, and additional allowed directories. Reads are much broader by default, including sensitive files unless you restrict them. Commands also inherit environment variables, which can contain credentials. Network requests pass through a proxy governed by your policy. See Anthropic's sandbox guide.
The important boundary is between a shell tool and the rest of the agent. Built-in file tools, hooks, and local integrations do not all pass through that shell sandbox. Protect those paths separately or place the whole process inside an outer environment. Anthropic's environment comparison explains the scope of each approach.
Keep the project itself disposable where possible. A sandbox can prevent access to your home directory while still allowing an agent to break every file in the checkout you gave it. A fresh branch and a reviewable diff remain useful controls.

Enable it and check the effective configuration

Open a Claude Code session and enter /sandbox. On Linux or WSL2, install missing dependencies reported by the panel. Ubuntu and Debian users normally need:
sudo apt-get install bubblewrap socat
Restart Claude Code after installing dependencies. Select the sandbox mode, then inspect the resolved configuration. Check the startup behavior as well as the interactive toggle: a machine missing required sandbox support should not silently become your unrestricted execution host.
For personal settings across projects, edit ~/.claude/settings.json. A repository can share .claude/settings.json, while .claude/settings.local.json holds local project choices. Organization policy has its own managed settings. These sources combine; reading one file does not tell you the complete effective policy. Anthropic documents the settings scopes and precedence.
Use the following as a small starting point for a trusted Node project. Merge it into your existing user settings rather than replacing unrelated configuration. The strict network setting belongs in user or managed settings, not a committed repository settings file.
{
  "sandbox": {
    "enabled": true,
    "failIfUnavailable": true,
    "allowUnsandboxedCommands": false,
    "autoAllowBashIfSandboxed": true,
    "filesystem": {
      "allowWrite": ["~/.npm"],
      "denyRead": ["~/.ssh", "~/.aws", "~/.config/gh"]
    },
    "network": {
      "allowedDomains": ["github.com", "registry.npmjs.org"],
      "strictAllowlist": true
    }
  }
}
failIfUnavailable refuses startup when enabled sandboxing cannot start. allowUnsandboxedCommands: false disables the unsandboxed retry. strictAllowlist rejects hosts outside the effective allowlist and requires v2.1.219 or later. That effective list can include domains from WebFetch allow rules, not just the two hosts above. See the settings reference.
There are no command exclusions in this example. Inspect inherited exclusions, broader write paths, and whether filesystem isolation has been disabled. Package downloads may need more hosts; add them only after inspecting the failure.
Settings scope matters for unattended workers. Since v2.1.285, a user-level allowUnsandboxedCommands: false holds against a project setting it to true, but other repository settings can still widen the boundary. Setting it to false through managed settings or --settings makes the sandbox admin-required and ignores repository settings that loosen it. Check the deployed version and Anthropic's strict-mode rules.

Permissions, secrets, and unattended execution

Permission modes decide whether an action is approved. Isolation limits what the running action can reach. Auto mode uses a classifier for applicable actions; it does not create a separate machine. Plan mode can run exploratory shell commands, so describing it as “no commands run” is incorrect. See the current permission-mode documentation.
The same distinction applies to --dangerously-skip-permissions. Removing prompts does not place file tools or helper processes inside the Bash sandbox. Anthropic recommends whole-process isolation for that usage. Run as a non-root user, apply the outer environment's restrictions, and review the output before merging.
Protect secrets across both access paths. sandbox.filesystem.denyRead limits sandboxed shell reads; built-in Read uses the permission system. Apply appropriate Read deny rules too. Avoid putting production credentials in a repository the agent can inspect.
Current releases also support sandbox.credentials for denying or masking selected credential files and environment variables. These controls require deliberate configuration; enabling the sandbox alone does not activate them. Masking has additional proxy and platform conditions, so use the documented credential settings rather than copying an old claim that credentials can never be protected.
For an automated job, give it a narrowly scoped account and only the repository access it needs. Use test data for the first run. Remove temporary credentials when the job ends. A boundary around compute cannot undo a valid database deletion or a push performed using an overpowered token.

Test the boundary before running a real job

Ask Claude to execute each probe through its shell tool in a disposable checkout. Your ordinary terminal follows a different execution path, and ! shell-mode behavior varies by session and policy. Confirm which tool ran each probe.
Choose a new filename before trying the write probes. Never overwrite an existing file just to test isolation.
Probe
Expected result with the example policy
Create a uniquely named file inside the checkout
Allowed
Create a uniquely named file directly in your home directory
Denied, assuming home was not separately allowed
Request headers from https://registry.npmjs.org
Allowed, subject to ordinary connectivity
Request headers from an unlisted host
Denied by strict allowlisting, assuming no other loaded rule permits it
Read a harmless fixture placed in a denied directory
Denied through the sandboxed shell path
Use a dummy fixture rather than reading a real private key. Record the tool used, the resolved settings, and the error. A request that fails because DNS is unavailable proves less than a policy rejection. Conversely, an unexpected success can indicate an inherited allow rule, a command exclusion, or execution outside the sandbox.
After these checks, run the actual dependency installation and tests. That catches missing registries, toolchain downloads, and cache paths before you leave a longer job unattended. Keep a record of each exception you add and the build step that requires it.

Choose a Claude sandbox for your hosted workload

Workload
Useful starting point
What to verify
Interactive coding in your own trusted repository
Built-in shell sandbox
Effective read, write, and network policy
Whole-process restrictions without Docker
Anthropic Sandbox Runtime
Policy around the CLI and its child processes
Repeatable team development environment
Dev container
Mounts, credentials, user, and outbound access
Hosted agent that edits files and runs ordinary tools
Standard gVisor sandbox
Tool compatibility, resource needs, and persistent paths
Docker or Compose builds inside the instance
Full VM
Docker installation, storage location, and network policy
Anthropic's open-source Sandbox Runtime can wrap an entire process with filesystem and network restrictions. It is a separate deployment choice from enabling the shell sandbox inside Claude Code. Its configuration and platform behavior should be evaluated for your process tree.
For a shared development environment, Anthropic's dev-container guide covers installation, authentication persistence, and network restrictions. Writable mounts still expose the mounted files. Credentials accessible inside a container remain sensitive. The guide explicitly cautions against treating a dev container as complete protection from a malicious project.
If you are building an application around the SDK, use our Claude Agent SDK sandbox guide for worker deployment, tenant separation, and SDK configuration. The settings here target Claude Code sessions; do not assume an SDK accepts the same top-level configuration.
For the kernel distinction behind these choices, read our microVM versus container guide. Choose based on the operations the agent must perform, then test the configuration you will actually deploy.

Run Claude Code in an Agent37 sandbox

Agent37 supplies the execution environment. The agent37-claude-code template supplies Claude Code and its gateway, with a terminal and file browser. It is a lean template without a bundled browser or desktop. Connect your own account using claude auth login, a token from claude setup-token, or ANTHROPIC_API_KEY, as described in the Claude Code template documentation.
Model usage is separate from Agent37 infrastructure charges. Do not assume a sandbox balance includes Claude inference or that an API key becomes inaccessible merely because it is stored inside an isolated instance.
Use the standard gVisor runtime for compatible workloads that need shell execution, files, and persistence. It shares host resources and cannot run a Docker daemon. If the job runs docker build or docker compose, choose a full VM.
Agent37's VM reference documents a separate Linux kernel and KVM access. The agent37-ubuntu VM template includes Docker. A custom image needs its own software and entrypoint; there is no systemd init by default. Keep Docker data and other durable state on the billed disk.
A VM supplies the kernel environment for nested tools; check that Claude Code's inner sandbox actually starts inside it. Run a dependency install and representative test, then stop and restart the instance and confirm the checkout survives. These are acceptance checks to run on your workload, not a benchmark measured for this article.

What the infrastructure costs

The following estimates use 2 vCPU, 4 GB RAM, and 4 GB retained disk, with a 730-hour month. Rates were verified against Agent37 pricing on November 1, 2026. They exclude model and tool charges.
Usage
Standard gVisor
Full VM
Running for all 730 hours
$4.76
$11.36
Running for 60 hours, disk retained for all 730 hours
About $0.72
About $1.26
Stopped for the full month, 4 GB disk retained
$0.36
$0.36
Standard monthly compute is 2 × $0.80 + 4 × $0.70 = $4.40. Disk adds 4 × $0.09 = $0.36. VM compute costs 2.5 times standard compute, so its always-running total is $11.00 + $0.36 = $11.36.
For the 60-hour example, prorate compute by 60 / 730 and add the full month's disk charge. An awake but idle instance still incurs compute charges. Stopping or sleeping pauses compute, while keeping the disk continues storage billing. Auto-sleep must be enabled; it is not a promise that every idle agent becomes free.
The VM price also depends on disk size. Omitting resources on agent37-ubuntu gives its documented 12 GB disk default: $12.08 for 730 running hours at 2 vCPU and 4 GB RAM. Choose enough disk for images and build cache.
Eligible new Cloud accounts can receive $5 starter credit after adding a card, but that credit does not unlock VMs. The billing rules require a real top-up for VM creation. Model access remains separate; a low infrastructure invoice does not make a long Claude run free.

Fix compatibility problems without losing the boundary

Treat each failure as a specific missing capability. If a package manager cannot write its cache, grant that cache path. If a download is blocked, identify the destination and decide whether it belongs in the policy. A broad filesystem exception changes much more than the build step you are trying to repair.
Do not expose a host Docker socket as a routine fix for a failed command. Docker access can give the workload extensive control over the machine running that daemon. A VM with its own daemon is a clearer deployment choice when container building is part of the job.
If bubblewrap fails inside a container, inspect the namespace restrictions of that environment. Anthropic documents a weaker nested-sandbox option, but enabling it changes the protection you get. Do not advertise it as equivalent to a configuration you have not tested.
TLS failures also deserve inspection. Check proxy configuration, certificate trust, and the actual error before widening network access. Keep package installation and a representative test run in your acceptance check so policy changes remain tied to real requirements.

Frequently asked questions

Is the built-in sandbox free?

There is no separate sandbox feature fee, but you still need Claude Code access and somewhere to execute it. A machine you already own may have no additional hosting invoice. Hosted compute and model usage are separate costs.

Does a sandbox make untrusted code safe?

It reduces the resources available to that code. Anything intentionally exposed, including writable files, credentials, and permitted services, remains part of the risk. Review the security guidance and use a disposable environment for unfamiliar repositories.

Does the sandbox work on Windows?

Use WSL2 for the built-in Linux sandbox, or choose an outer container or VM environment. Do not assume a native Windows session gains shell sandboxing just because the same settings file works on another machine.

Will the agent keep its files after stopping?

Agent37 keeps billed disk through documented lifecycle operations. On VMs, start and resize cold-boot the machine, so save durable state under $HOME. Auto-sleep may restore a memory checkpoint but can fall back to a cold boot. Keep files and backups as the recovery path.
Start with one representative repository, confirm the boundary, and measure its disk and running time. When it needs its own hosted environment, create an Agent37 sandbox and follow the instance API reference. Choose standard gVisor for compatible agent execution or a full VM when the workload needs Docker or its own kernel.
Vishnu

Written by

Vishnu

Founder at Agent37, which runs managed hosting for OpenClaw and Hermes agents for 1,000+ users. Writes about what actually breaks when you leave an AI agent running.