Why it matters
An agent that writes and runs code, or drives a browser, will eventually run something wrong: a recursive delete, a request to an internal endpoint, a package installed from a typo. The model cannot be relied on to avoid these, and the consequences depend entirely on what the process may reach. Sandboxing converts a class of catastrophic outcomes into failed steps the agent can observe and correct.
Mental model
A sandbox is a fenced yard, not a trained dog. The metaphor breaks because a fence is a fixed perimeter, while an agent's needs change per task, so the boundary must be configured per run and is only as good as that configuration.
How it works
- trusted · hostoutside the boxtrustedAgent orchestrator
- must not crosstrustedProduction credential
- neutral · sandbox · one runown credentialneutralTask credential · short-livedscoped to the run
- Agent orchestrator· task + toolsProduction credential· token mountedcredential scope · openuntrusted workloadneutralAgent code + toolsneeded callegress allowlist · open
- untrusted · networkneeded calluntrustedAllowlisted host
- Agent code + tools· exfil / internalegress allowlist · openoff-listuntrustedAny other host
boundary. The orchestrator starts one run with a defined job. The boundary is chosen from the threat model: a container, a microVM or a separate account, each with a different kernel story.
Figure. The boundaries are the credential scope and the egress allowlist, drawn on separate edges. They refuse a mounted production token and connections off the list; they do not remove the authority of the task credential inside the box. Resource caps and kernel isolation are separate decisions and are not drawn. Shown with both controls open; use Blocked on each to apply it.
What to notice. Residual risk: a container shares the host kernel, so this is not the same boundary as a microVM. A permitted host that proxies to an unpermitted one bypasses the allowlist; log resolved destinations, not only hostnames.
Text version
Three zones: TRUSTED · HOST holds the orchestrator and a production credential; NEUTRAL · SANDBOX · ONE RUN holds the agent code and tools plus a short-lived task credential; UNTRUSTED · NETWORK holds an allowlisted host and any other host. A solid path runs from the orchestrator to the code, labelled task and tools. A dashed red path runs from the production credential to the code, labelled token mounted, and is the only edge under the credential-scope control. A solid path runs from the task credential to the code, labelled scoped to the run, and a solid path runs from the code to the allowlisted host. A dashed red path runs from the code to any other host. Both code-to-network edges are under the egress allowlist: open, both leave; blocked, the allowlisted call gets a teal tick and the off-list path is cut at a teal bar.
- Choose the isolation boundary: a container, a microVM, a separate account or a throwaway project.
- Mount only the directories the task needs, read-only where possible, and discard the filesystem after the run.
- Deny network egress by default and allowlist specific hosts and ports for the task.
- Inject short-lived credentials scoped to the task instead of mounting host or production secrets.
- Cap CPU, memory, disk and wall-clock so a runaway process fails fast rather than consuming the host.
- Capture stdout, stderr and exit codes as observations so the agent can react to a blocked action.
Trade-offs
| Choice | Good for | Cost | Fails when |
|---|---|---|---|
| Container on the host | Fast start, simple tooling | Shares the kernel, weaker isolation | Code is untrusted or hostile |
| MicroVM per run | Strong isolation, clean teardown | Slower start and higher overhead | Runs are short and numerous |
| Full network access | Fewest task failures | Exfiltration and internal reachability | The agent reads untrusted content |
| Persistent workspace | State carries between steps | Leaks between runs and users | Several tenants share the sandbox |
Good for
Fast start, simple tooling
Cost
Shares the kernel, weaker isolation
Fails when
Code is untrusted or hostile
- Code is untrusted or hostile
- Runs are short and numerous
- The agent reads untrusted content
- Several tenants share the sandbox
Figure. Each choice with what it buys, what it costs, and the case where it loses.
What to notice. The fourth column is the decision: if the losing case describes your situation, the choice is wrong.
Text version
Four trade-offs: Container on the host is good for Fast start, simple tooling, costs Shares the kernel, weaker isolation, and fails when Code is untrusted or hostile. MicroVM per run is good for Strong isolation, clean teardown, costs Slower start and higher overhead, and fails when Runs are short and numerous. Full network access is good for Fewest task failures, costs Exfiltration and internal reachability, and fails when The agent reads untrusted content. Persistent workspace is good for State carries between steps, costs Leaks between runs and users, and fails when Several tenants share the sandbox
Failure modes
- Secret in the environment. The agent reads a token from the environment and uses it outside its scope. Debug: enumerate environment variables and mounted files inside the sandbox and diff against the allowlist.
- Egress allowlist bypass. A permitted host proxies to an unpermitted one. Debug: log resolved destinations, not just hostnames, and test with a known redirect.
- Resource exhaustion. A runaway process starves the host and other runs stall. Debug: check cgroup limits and the distribution of run durations.
In production
Monitor sandbox start latency, blocked egress attempts and resource kills. Rehearse an escape attempt in staging and confirm the run fails without touching the host.
Common misconceptions
People think: A container is a security boundary by default.
Actually: A shared-kernel container limits damage but is not equivalent to a VM boundary against hostile code.
People think: Sandboxing slows agents down for little benefit.
Actually: Most of the cost is start time; the benefit is that a destructive step becomes a recoverable error.
Interview angle
Strong answers name the boundary, the egress policy and the credential model, then discuss start-up cost and what the agent sees when a call is blocked. Weak answers say the code runs in Docker and never mention network, secrets or resource limits.
Sources
- gVisor documentation — user-space kernel isolation and its limits relative to a VM.
- OWASP, Top 10 for Large Language Model Applications — excessive agency and unsafe execution of model-directed actions.