On this page#
- The definition
- Why the Claude Code sandbox exists
- How it actually works
- When you need it and when you do not
- The part vendors leave out
- FAQ
The definition#
A Claude Code sandbox is an execution boundary that limits what Claude Code can read, change, execute, and reach while working on your machine. It reduces the blast radius of agent-generated commands, but it does not prove those commands are correct or make an unsafe repository safe by default.
The key distinction is between capability and correctness. A sandbox constrains capabilities: filesystem access, command execution, and network access. Your tests, review process, and repository invariants still determine correctness.
Claude Code is Anthropic’s agentic coding tool: it can inspect a codebase, edit files, and run development commands. Once an agent can execute commands rather than merely suggest code, its permission boundary becomes part of the engineering system—not an optional security accessory.
A useful mental model is:
The sandbox decides what the agent is allowed to affect. Your validation decides whether the resulting change is acceptable.
That separation matters. Treating sandboxing as automatic correctness is a category error.
Photo by Snapwire on Pexels.
Why the Claude Code sandbox exists#
The sandbox exists because confirmation prompts do not scale to agentic work. An engineer who approves commands one at a time either becomes the bottleneck or starts approving mechanically. The first outcome destroys autonomy; the second turns the prompt into security theater.
Before sandboxed execution, teams generally chose among three weak patterns:
- Run the agent with the developer’s normal account and trust every generated command.
- Require approval for nearly every operation.
- Put the entire workflow inside a disposable VM or container.
The first gives the agent the same reach as the engineer, including credentials, unrelated repositories, and user-level configuration. The second creates alert fatigue. The third can provide strong isolation, but it adds environment maintenance and often diverges from the real development setup.
The Claude Code documentation should be the source of truth for supported controls. The important design shift is broader than any single setting: routine operations can proceed inside a predefined boundary, while actions that cross that boundary require a deliberate decision.
That changes the engineer’s job. Instead of repeatedly asking, “Is this command safe?”, you define durable rules:
- Which paths are legitimate inputs?
- Which paths may be modified?
- Which commands are part of normal development?
- Which network destinations, if any, are necessary?
- Which actions must always stop for review?
This is the same discipline used for CI workers and production services: grant the capability required for the task, not the capability available on the machine.
How it actually works#
A Claude Code sandbox works by mediating effects, not by understanding intent. It can restrict where processes operate and what external resources they reach; it cannot determine whether a permitted edit violates an architectural rule, corrupts a fixture, or silently changes business behavior.
That mechanism has several layers:
| Layer | What it controls | What it cannot guarantee | |---|---|---| | Filesystem boundary | Files and directories available to the agent | That allowed edits are logically correct | | Command boundary | Whether tools and subprocesses may run | That an allowed command is harmless | | Network boundary | Whether processes can contact external services | That an approved destination returns safe content | | Approval boundary | When human authorization is required | That the human reviews carefully | | Repository validation | Tests, linters, type checks, policy scripts | That the sandbox itself is correctly scoped |
The practical configuration task is to turn repository invariants into boundaries. Start with the smallest working surface:
- Include the repository and required toolchain inputs.
- Exclude credential stores, unrelated worktrees, personal configuration, and production artifacts.
- Permit writes only where the task can legitimately create changes.
- Keep network access closed unless the task actually requires it.
- Route exceptional operations through explicit approval.
Do not begin by allowing the whole home directory because one build step fails. That is the sandbox equivalent of disabling a firewall to fix a connection problem. Identify the missing dependency and expose only that dependency.
The official Claude Code overview explains the agent’s operating model; use the current Claude Code docs for the exact controls available in your installation. The policy should describe the intended trust boundary even if the product’s configuration surface changes.
Sandbox denials are also useful diagnostics. A blocked command often reveals hidden coupling: a test reading global configuration, a build writing outside the repository, or a script depending on undeclared network access. Fixing that coupling usually improves CI reproducibility as well as agent safety.
Photo by Jakub Zerdzicki on Pexels.
When you need it and when you do not#
You need a sandbox when the agent can execute commands against a valuable environment and the requested work does not require unrestricted access. You do not need one for read-only conversation, disposable environments with no credentials, or workflows where every proposed command is inspected and executed manually.
Use a Claude Code sandbox when any of these are true:
- The repository contains credentials, proprietary code, customer-derived data, or release tooling.
- The agent runs package managers, test scripts, code generators, migrations, or shell commands.
- Multiple repositories or sensitive user files are reachable from the same account.
- Engineers want longer autonomous runs without approving routine operations.
- The workflow will become a shared team practice rather than a personal experiment.
A sandbox is less valuable when the agent only produces patches for manual application. It may also be redundant inside a genuinely disposable environment that contains no reusable credentials and has no access to valuable external systems.
“Inside a container” is not enough evidence. A container with mounted credentials, a writable source checkout, and production network access still has a large blast radius. Judge the effective permissions, not the label attached to the environment.
For team adoption, define a baseline policy in repository terms:
- Document the paths and commands required for normal verification.
- Make tests, linting, and type checks runnable inside the boundary.
- Treat new permission requirements as code-reviewable design changes.
- Keep escape hatches visible and exceptional.
- Test recovery before allowing unattended work.
If your team is still establishing those repository-level habits, PairFoundry Foundations provides the more important starting point: clear task boundaries, verification, and review discipline. Sandboxing strengthens that workflow; it cannot replace it. The broader PairFoundry packs cover the available practice bundles.
The part vendors leave out#
Sandboxing transfers work; it does not remove it. You spend less attention approving routine commands, but more attention defining boundaries, eliminating hidden dependencies, handling denials, and maintaining a recovery path. That is a good trade for serious repositories, but it is still a trade.
The first limitation is that permitted damage remains damage. If the agent may rewrite the repository, it can delete an allowed file, produce a misleading migration, or make a broad but syntactically valid refactor. Version control, small commits, tests, and review remain mandatory.
The second limitation is configuration drift. A policy that works for one branch or machine may fail when the toolchain changes. Teams often respond by widening access until failures disappear. That practice is wrong: every denial should be classified as a missing legitimate dependency, an accidental dependency, or an action that should remain blocked.
The third limitation is the approval escape hatch. If engineers routinely override the boundary, the documented policy is not the effective policy. Track the reasons for overrides and either support the operation narrowly or redesign the workflow.
The fourth is false confidence around secrets. Blocking direct reads from a credential directory does not help if credentials are already present in environment variables, command output, build logs, mounted sockets, or reachable helper processes. The boundary must cover indirect access paths too.
Recovery should therefore be designed before autonomy:
- Start from a clean working tree or an intentional checkpoint.
- Keep unrelated changes outside the agent’s writable scope.
- Review the diff before accepting generated work.
- Run repository validation independently of the agent’s narrative.
- Revert changes through version control when invariants fail.
- Rotate credentials if exposure is plausible; reverting files cannot undo disclosure.
Sandboxing belongs to a layered workflow, alongside repository hygiene and deterministic verification. For more concise explanations of adjacent engineering terms, see PairFoundry’s plain definitions.
Photo by Daniil Komov on Pexels.
Related reading#
- GitHub Copilot SDK: the definition, and the part vendors leave out
- Claude Code permissions — a plain explanation for people with a real repo
FAQ#
Should every engineer on a team use the same sandbox policy?#
Yes for the baseline, but not necessarily for every task. The repository should define the minimum paths, commands, and verification steps required for normal work. Task-specific exceptions can be narrower or temporary, but undocumented personal allowlists create inconsistent risk and failures that teammates cannot reproduce.
Treat policy changes like build configuration changes: explain why the capability is needed, keep the scope small, and review the effect on everyone using the repository.
How is sandboxing different from approving each command?#
Sandboxing approves classes of effects in advance; command prompts ask for individual decisions during execution. A well-scoped boundary lets routine work continue while blocking unexpected reach. Repeated prompts encourage mechanical approval and provide weaker protection once the engineer stops evaluating each command carefully.
Approval is still appropriate for rare boundary crossings. It should not be the main control for ordinary test, build, and editing operations.
What should I do when the sandbox breaks a build or test?#
Treat the denial as evidence, not an obstacle to bypass. Identify the exact file, process, or network dependency; decide whether it is legitimate; then expose only the smallest required capability. If the dependency is accidental, fix the build instead of widening the sandbox.
Record the reason for any policy change. “The command failed” is not a sufficient justification for broader access.
Can I roll back everything if an agent makes a bad change?#
You can usually roll back tracked repository changes with version control, but not every side effect is reversible. Published packages, external API calls, database writes, deleted untracked files, and disclosed credentials may survive a code rollback.
Keep external write access outside the routine sandbox, checkpoint before substantial work, and review both the diff and command effects before accepting the result.
When should I avoid using a Claude Code sandbox?#
Avoid adding it when no code executes, when you only want suggested patches, or when an existing disposable environment already provides a smaller verified boundary. Also avoid pretending a badly configured sandbox is protection: broad filesystem, credential, and network access can be worse than explicit manual execution because it encourages unattended trust.
Use the sandbox when its boundary is concrete, inspectable, and aligned with the task—not merely because the feature exists.