Lesson 53.4 · 4 of 5 · 6 min read · Reviewed 24 Nov 2026
Sandboxing specialised agents
By the end, you can
- Choose a sandbox level for a coding, research or browser agent.
- Limit files, network, secrets and time for each agent run.
A coding agent runs tests. A research agent downloads pages. A browser agentBrowser agent: An agent that navigates websites by reading pages and clicking, typing and scrolling. clicks around websites. Each of them executes things that nobody has reviewed yet, steered by text that may come from strangers. A sandboxSandbox: An isolated environment that limits what code or an agent can reach, such as files, network or credentials. makes sure that, whatever happens, the damage stays inside a box you can throw away.
Levels of isolation
| Level | Example tools | Start-up | Isolation | Good for |
|---|---|---|---|---|
| Restricted process | OS sandbox profiles, seccomp, the sandbox mode in some coding agents | Instant | Basic | Your own trusted repo, on your machine |
| Container | Docker, Podman | Seconds | Good, shares the host kernel | Most agent runs in CI |
| Hardened container | gVisor | Seconds | Stronger: a user-space kernel in between | Untrusted code at scale |
| Micro-VM | Firecracker, Kata Containers | About a second | Strong: its own kernel | Multi-tenant products |
Pick the level by asking whose code and whose content the agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. will touch. Your own repo on your laptop is low risk. Pull requests from strangers, or arbitrary websites, are high risk.
The four limits
- Files. Mount only the repo or working folder, read-only where possible. No home directory, no SSH keys.
- Network. Default deny. Allow only what the task needs: the package mirror for a coding agent, a search API for a research agent, a list of domains for a browser agent.
- Secrets. Pass short-lived, narrow tokensToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id. through environment variables, or none at all. Never mount a cloud credentials file.
- Time and resources. CPU, memory and a wall-clock limit, so a runaway test or an endless crawl is killed.
# A sketch of a per-run sandbox policy (illustrative, not any one tool's format)
image: python:3.12-slim
mounts: [{src: ./repo, dst: /work, readonly: false}]
network: {default: deny, allow: [pypi.org, files.pythonhosted.org]}
env: {} # no secrets
limits: {cpus: 2, memory: 2g, timeout: 15m}
after: [copy /work/patch.diff, destroy]
Per agent type
| Agent | Extra care |
|---|---|
| Coding | Run tests inside; return only the diff and test log |
| Research | Fetch pages in the box; strip scripts; treat page text as data |
| Browser | Fresh browser profile; no saved passwords; domain allow-list; confirm risky clicks |
Common mistakes
- Sandboxing the tool but not the tests. The test runner executes the same untrusted code.
- A wide-open network. Isolation of files means little if the agent can send them anywhere.
- Reusing one box. State left from a previous run, such as cached tokens or files, leaks into the next.
- Relying on the prompt. “Do not delete files” is a request. A read-only mount is a guarantee.
Key points
- Specialised agents run code, open pages and touch files, so each run belongs in a sandbox, not on a person's machine.
- Sandboxes range from restricted processes to containers to micro-VMs; stronger isolation costs more start-up time.
- Limit four things: the files it can see, the network it can reach, the secrets it holds and the time and resources it can use.
- Throw the sandbox away after the run and keep only the outputs you asked for, such as a diff or a report.
Check sandbox policies before a run
Write a checker that reviews a sandbox policy against the four limits (files, network, secrets, time) before an agent run is allowed.
You will have: A function that returns a list of problems for each policy, and a printed verdict for three sample policies.
Steps
- Read the three sample policies in the starter: one per agent type.
- Flag mounts of home folders, SSH or cloud credential paths.
- Flag networks that are not default-deny, and secrets passed into untrusted runs.
- Flag missing CPU, memory or timeout limits, and boxes that are reused rather than destroyed.
- Print each policy's problems and whether the run may start.
Done when
- The coding policy passes with 0 problems.
- The research policy is blocked for its open network and missing timeout.
- The browser policy is blocked for mounting the home folder and passing a secret.
Open in the Playground No API key needed.
Starter code (Python)
POLICIES = {
"coding": {"mounts": ["./repo:/work"], "network": {"default": "deny", "allow": ["pypi.org"]},
"secrets": [], "limits": {"cpus": 2, "memory": "2g", "timeout": "15m"}, "destroy_after": True, "untrusted": True},
"research": {"mounts": ["./out:/out"], "network": {"default": "allow"}, "secrets": [],
"limits": {"cpus": 1, "memory": "1g"}, "destroy_after": True, "untrusted": True},
"browser": {"mounts": ["~/:/home/agent"], "network": {"default": "deny", "allow": ["shop.example"]},
"secrets": ["SHOP_TOKEN"], "limits": {"cpus": 1, "memory": "2g", "timeout": "10m"}, "destroy_after": False, "untrusted": True},
}
def check(p):
problems = []
# TODO: files: flag mounts whose source starts with "~" or "/home", or contains ".ssh" or ".aws"
# TODO: network: flag a default that is not "deny"
# TODO: secrets: flag any secret when the run is untrusted
# TODO: limits: flag missing cpus, memory or timeout; flag destroy_after False
return problems
for name, p in POLICIES.items():
probs = check(p)
print(name + ":", len(probs), "problems", probs, "->", "start" if not probs else "blocked")
Show a solution
POLICIES = {
"coding": {"mounts": ["./repo:/work"], "network": {"default": "deny", "allow": ["pypi.org"]},
"secrets": [], "limits": {"cpus": 2, "memory": "2g", "timeout": "15m"}, "destroy_after": True, "untrusted": True},
"research": {"mounts": ["./out:/out"], "network": {"default": "allow"}, "secrets": [],
"limits": {"cpus": 1, "memory": "1g"}, "destroy_after": True, "untrusted": True},
"browser": {"mounts": ["~/:/home/agent"], "network": {"default": "deny", "allow": ["shop.example"]},
"secrets": ["SHOP_TOKEN"], "limits": {"cpus": 1, "memory": "2g", "timeout": "10m"}, "destroy_after": False, "untrusted": True},
}
def check(p):
problems = []
for m in p["mounts"]:
src = m.split(":")[0]
if src.startswith("~") or src.startswith("/home") or ".ssh" in src or ".aws" in src:
problems.append("files: mounts " + src)
if p["network"].get("default") != "deny":
problems.append("network: default is not deny")
if p["untrusted"] and p["secrets"]:
problems.append("secrets: " + ", ".join(p["secrets"]) + " in an untrusted run")
for k in ("cpus", "memory", "timeout"):
if k not in p["limits"]:
problems.append("limits: no " + k)
if not p["destroy_after"]:
problems.append("reuse: box is not destroyed")
return problems
for name, p in POLICIES.items():
probs = check(p)
print(name + ":", len(probs), "problems", probs, "->", "start" if not probs else "blocked")