Permission rules decide whether an action runs. A sandbox decides what it can reach once it does. That difference matters because, as the least privilege guide showed, rules match the text of a command, and the same program can be invoked a dozen other ways. A sandbox is enforced by the operating system, so it doesn't care how the command was spelled.

What a sandbox does and doesn't do

A sandbox limits three things: files (what can be read and written), network (where traffic can go) and processes (what runs and with which environment). It doesn't change two things people often assume it does:

  • What the model sees. Files the agent reads are still sent to the model provider, sandbox or not.
  • What it's allowed to touch. A writable project folder can still be wrecked, and any allowed network route can still carry data out.

So a sandbox shrinks the blast radius. It doesn't make a compromised agent harmless.

Four levels of isolation

LevelWhat's isolatedExamples
Per-command sandboxEach shell command and its child processesClaude Code's sandboxed Bash, using Seatbelt on macOS and bubblewrap on Linux
Whole-process sandboxThe agent itself, including its file tools, hooks and MCP serversAnthropic's open-source sandbox runtime wrapping Claude Code
ContainerA separate filesystem and process space, sharing the host's kernelDev containers, Hermes's Docker backend, OpenClaw's Docker sandbox
Virtual machine or remote boxA separate operating systemA local VM, Hermes or OpenClaw over SSH, cloud sessions

Each step up costs more setup and gives a stronger wall. A container shares your kernel, so a kernel bug is a way out. A VM doesn't.

Know what's outside the boundary

The most common mistake is assuming "sandbox on" covers everything. It usually doesn't.

  • Claude Code's sandbox wraps shell commands only. The built-in Read, Edit and WebFetch tools follow permission rules instead, and hooks and local MCP servers run directly on your machine. A sandbox denyRead doesn't stop the Read tool. To put everything behind one wall, run the whole process in the sandbox runtime, a container or a VM.
  • OpenClaw moves only tool execution. The Gateway, which holds sessions and channel connections, always stays on the host.

Before trusting a sandbox, list what the agent runs and mark which pieces are inside it.

Close the escape hatches

Sandboxes come with ways out, usually for good reasons. Know each one:

  • The unsandboxed retry. When a command fails in Claude Code's sandbox, Claude can retry it outside. Depending on your mode you're asked first, but a matching allow rule approves the retry too: allow Bash(curl *) and a blocked curl can rerun unsandboxed with no prompt. Turn it off with "allowUnsandboxedCommands": false.
  • Excluded commands. Anything in excludedCommands runs with full access and no network proxy. Only list tools you'd trust with your whole machine.
  • Config files as a way out. A command that can write the agent's own config can grant itself permissions or add a hook that runs outside the sandbox. That's why Claude Code's sandbox blocks writes to .claude settings, hooks, .mcp.json, shell startup files like .zshrc, and .git/hooks, even inside folders it can otherwise write. If you build your own container, protect the same classes of file.

The network is your exfiltration boundary

Anything the agent can read can leave through any connection it can open. Network rules matter more than file rules:

  • Default deny, then allowlist. Claude Code's sandbox sends traffic through a proxy whose allowed domains start empty. OpenClaw's Docker sandbox defaults to no network at all.
  • Allowing a domain allows everything it accepts. If a code host, file-sharing site or paste service is on the list, it can receive your data as easily as it serves packages. Allow specific API hosts over broad wildcards.
  • Block the metadata endpoint. On cloud machines, 169.254.169.254 hands out credentials. Claude Code's proxy refuses a hostname that resolves only to local addresses like that one. Check that your own setup does too.

Mounts decide what's reachable

In a container, what you mount is what the agent can reach:

  • Mount the project, not your home folder. OpenClaw's default doesn't expose the agent workspace at all; you can choose read-only or read-write.
  • Mount credentials read-only, or not at all. Hermes mounts credential files read-only into Docker.
  • Never mount the Docker socket. Whoever controls the Docker daemon can start a privileged container with the host's filesystem mounted, which effectively means control of the host.
  • Keep the default hardening. OpenClaw's Docker sandbox runs with a read-only root filesystem and every Linux capability dropped; Hermes drops capabilities, blocks privilege escalation and caps the number of processes. Don't loosen those to fix a failing install.

Which one to use

SituationStart with
Everyday work on your own machine, fewer promptsA per-command sandbox with a network allowlist
Letting an agent run unattended or skip promptsA container, VM or the whole-process sandbox runtime
An unfamiliar repo or untrusted contentA VM or a throwaway remote machine
A chat agent with real toolsThe Docker or SSH backend, with no network by default

Sandbox checklist:

  • Sandbox on, and you know which tools and processes sit outside it
  • Unsandboxed retry off, and excluded commands kept to a minimum
  • Network default-deny, with specific hosts allowed
  • Only the project mounted; no home folder, no ~/.ssh, no Docker socket
  • Unattended runs only inside a container, VM or remote machine

Go deeper: Least privilege for AI agents · Secrets and API keys when agents run code · Claude Code permission modes · Prompt injection