Topic 1 of 5 · 4 min read
Built-in sandboxes in agent CLIs
Goal: Configure an agent CLI's built-in sandbox and state which file reads, writes and network calls it still allows.
A built-in sandbox makes the operating system enforce limits on what an agent's commands can touch, so a bad command fails even when the model, or an attacker steering it, wants it to run.
Check yourself · 1 of 3
What does an OS-level sandbox in an agent CLI do that a permission prompt does not?
Why it matters
A coding agent runs shell commands as you. Without limits, a command can read your SSH keys, edit files outside the project or send data to any server. Permission prompts help, but people click "allow" when they are tired. A sandbox is a second wall that does not depend on anyone paying attention.
How it works
Agent CLIs use the sandbox tools their platform already has. Claude Code and Codex CLI use Seatbelt on macOS. On Linux they use bubblewrap, and Codex also uses Landlock, a kernel feature that lets a process restrict its own file access. The agent starts each command inside this boundary, and every child process inherits it.
Two limits matter most:
- Filesystem. Typically the project folder is writable, the rest of the disk is read-only or hidden, and sensitive folders such as
~/.sshstay blocked. - Network. Outbound connections are blocked or sent through a proxy that allows named domains only.
You need both. Without network limits, a compromised agent can send your files out. Without file limits, it can escape the network rules by editing your shell config or other trusted files.
Modes and approvals
Most tools offer a few modes: read-only, write inside the workspace, and full access with no sandbox. Sandboxing and approvals are different controls. The sandbox decides what is possible. Approvals decide when the agent must ask before trying something outside the box. A good setup is a tight sandbox with few prompts, because commands inside the box are already safe enough to run without asking.
Before and after
# Weak: no sandbox, no questions
sandbox_mode = "danger-full-access"
approval_policy = "never"
Every command can read and write anywhere you can, and nobody is asked. A safer version:
sandbox_mode = "workspace-write"
approval_policy = "on-request"
Writes stay in the workspace, and the agent asks before leaving it. Check your own tool's docs for exact setting names, because they differ and change.
What goes wrong
- Treating the sandbox as complete. It limits shell commands. Your editor, MCP servers and the agent's own process may run outside it.
- Turning it off when it blocks something. Add the one domain or folder that is needed instead.
- Allowing broad paths. Allowing your whole home folder defeats the point.
- Trusting it blindly. Test it: ask the agent to read a file you blocked and confirm it fails.
Examples
Testing the boundary
# Ask the agent to run these inside its sandbox
cat ~/.ssh/id_ed25519
curl -s https://example.org/
touch ../outside-project.txt
All three should fail or be refused. If one succeeds, the sandbox is off or too wide. Fix the config before giving the agent real work.
Opening one hole on purpose
A build needs registry.npmjs.org. Allow that single domain through the proxy and keep everything else blocked. Do not switch to full access to make npm install pass.
Key points
- A sandbox is enforced by the operating system, so it holds even when the model is wrong or manipulated.
- Agent CLIs build on Seatbelt on macOS and on bubblewrap or Landlock on Linux.
- Filesystem and network limits need each other; either one alone leaves a gap.
- The sandbox sets what is possible and approvals set when to ask, so use both.
- Verify the boundary by trying a blocked read and a blocked network call.
Common mistakes
- Switching to full access whenever a command is blocked.
- Assuming MCP servers and editor plugins run inside the same sandbox as shell commands.
- Allowing the whole home directory as writable.
- Never testing that the blocked paths are really blocked.
Check yourself · 2 of 3
Why does a coding agent sandbox need both filesystem and network limits?
Check yourself · 3 of 3
An agent's npm install is blocked by the sandbox. What is the best response?
Practice items, not counted towards your mastery.
Start here
- Sandboxing (Claude Code docs) (opens in a new tab)DocsFree
How a coding agent's sandbox limits files and network, and how it pairs with permission prompts.
- Making Claude Code more secure and autonomous with sandboxing (Anthropic) (opens in a new tab)ArticleFree
Why filesystem and network isolation must work together, explained by the team that built it.
- Docker Engine security (opens in a new tab)DocsFree
What containers isolate, what they share with the host, and how capabilities and the daemon socket matter.
More for this topic
- Landlock (Linux kernel docs) (opens in a new tab)DocsFree
How a process restricts its own file access at the kernel level.