Sandboxing: the room with no windows
You cannot stop the agent being fooled. You can decide what room it is standing in when it happens.
In 60 seconds
Sandboxing: the room with no windows
You cannot stop the agent being fooled. You can decide what room it is standing in when it happens.
The four walls
- 1
Filesystem
Its own directory or container. No host mounts. No access to~/.ssh,~/.aws, browser profiles or credential stores. A copy of what it needs, nothing more. - 2
Network
Deny by default, allow-list by exception. Block internal ranges and cloud metadata endpoints. Remember DNS — a lookup leaks data even when the connection is refused. - 3
Credentials
No ambient environment secrets. Short-lived, narrowly scoped tokens issued per run, and revocable in one action. - 4
Resources
CPU, memory, wall-clock time, spend. A runaway agent should hit a wall in seconds, not on your monthly invoice.
Levels of isolation
| Level | What it is | Good against | Weak against |
|---|---|---|---|
| Process | Run as a low-privilege user | Accidental file access | A determined escape |
| Container | Docker or similar | Most practical attacks | Kernel-level escapes, shared network |
| VM | A whole virtual machine | Nearly everything technical | Cost and start-up time |
| Separate machine | Physically isolated host | Blast radius on your network | Complexity |
| Ephemeral | Destroyed after every run | Persistence of any kind | Nothing — this is the best habit on the list |
What a sandbox does not do
- It does not stop the agent being fooled. It only limits what a fooled agent reaches.
- It does not protect data you deliberately put inside it. If you mounted the customer database, the sandbox is protecting an empty room.
- It does not cover the tools you gave it. A perfectly sandboxed agent with a live
send_emailtool can still email your secrets to the world.
Watch and read more
Lab
A sandbox you have actually tried to break out of.
The problem
docker run --rm \
--network none --memory 256m --cpus 0.5 --pids-limit 64 \
--read-only --tmpfs /tmp:size=16m \
--cap-drop ALL --security-opt no-new-privileges \
--user 65534:65534 \
-v "$PWD/work:/work:ro" -w /work \
python:3.12-slim timeout 10 python main.pyYou are done when
Hard questions
Try to answer before you reveal. If you can answer these, you understood the lesson.
Q1Your container is perfectly hardened. Your agent has a working send_email tool. What has the sandbox bought you?Reveal
Q2When is a container insufficient, and what is the concrete decision rule?Reveal
Questions people ask
Is a Docker container enough?
For most business applications, yes, when it is configured properly: no privileged mode, no host mounts, restricted network, read-only root filesystem where possible, and non-root user. For running genuinely untrusted code, use a VM or a purpose-built isolation runtime.
Should coding agents run in a sandbox?
Absolutely, and this is the single highest-value place to apply it. A coding agent reads attacker-writable text (issues, PRs, dependency docs) and executes commands. Sandbox it, and require explicit approval for network access and credential use.
How do I give the agent real data safely?
Give it a scoped copy, or better, a tool that answers questions about the data without handing the data over. "How many orders last week?" returns a number. It never needs the table.
Does sandboxing slow things down?
Container start-up costs a second or two, and you can keep warm pools. Compare that against a single incident. This is the cheapest insurance in the whole guide.
Lesson test
5 questions. Get 3 right (60%) to pass and complete this lesson.
Sign in with your phone number to take the test and save your progress