Lesson 1 of 5 · 3 min read
Isolation Boundaries
In this lesson
TL;DR: Treat model-written code as untrusted, because what it does depends on what the model read. Pick a boundary by what the code could reach if it escaped: a container shares the host's kernel; gVisor answers the code's system calls itself, so far fewer reach the host; a microVM (Firecracker, Kata) gives each run its own kernel behind a hypervisor; Wasm exposes only what you grant. Stronger isolation costs start-up time, compatibility or operational effort. Whatever you choose, add the same layers around it: no credentials inside, egress allowed only where needed, a scratch filesystem, and limits on CPU, memory, time and processes.
After this lesson, you should be able to explain why agent-generated code is untrusted, compare containers, gVisor, microVMs and Wasm by what they share and cost, choose one for a workload, and list the controls every sandbox needs regardless.
Before you read
Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.
1A data-analysis agent writes and runs Python on files users upload. A team says the code is safe because 'our own model wrote it'. Why is that wrong?
The options, by what they share
- 1
1 · Process on the host
no real boundary
- Same user, files, network and secrets as the service
Never for untrusted code
- 2
2 · Container
namespaces, cgroups, seccomp
- Shares the host kernel
- Fast start, full compatibility
Escape path: a kernel vulnerability
- 3
3 · gVisor
user-space kernel
- Intercepts system calls before the host kernel
- Some syscall and performance gaps
Much smaller host kernel surface
- 4
4 · MicroVM
Firecracker, Kata
- Own guest kernel behind a hypervisor
- Boots in a fraction of a second
Escape needs a hypervisor flaw
- 5
5 · WebAssembly
capability-based runtime
- Only granted capabilities exist
- Limited language and library support
Strong by construction, narrow by design
Containers are a process with a restricted view of the system (namespaces), resource limits (cgroups) and filtered system calls (seccomp). They start fast and run anything, but every container shares the host kernel, so a kernel vulnerability can cross the boundary.
gVisor implements much of the Linux system-call interface in a user-space kernel, so code in the sandbox talks to gVisor rather than directly to the host kernel. The host kernel's exposed surface shrinks considerably, at some cost in performance and compatibility.
MicroVMs run each workload with its own guest kernel inside a lightweight virtual machine. Firecracker, built for serverless platforms, is designed to start microVMs in a fraction of a second with a small memory footprint. Escaping requires a flaw in the hypervisor layer, a much smaller target.
WebAssembly runs code in a runtime that grants capabilities explicitly: no files, network or clock unless provided. It is strong by construction but runs only code compiled for it, so arbitrary Python with native packages is often impractical.
Choosing
| Workload | Reasonable choice | Why |
|---|---|---|
| Internal tool, trusted inputs only | Hardened container | Low risk, maximum compatibility |
| Model-written Python on user uploads, multi-tenant | gVisor or microVM per session | Untrusted code, other tenants nearby |
| Short functions, limited libraries, very high volume | Wasm | Fast, strong, narrow |
| Long coding sessions with full toolchains | MicroVM per session | Compatibility and a strong boundary |
Layers every sandbox needs
The boundary limits escape; these limit what code can do inside it.
- No credentials inside. Tokens stay outside; calls that need them go through a broker (next lesson).
- Egress control. Deny by default; allow package mirrors or specific APIs only.
- Scoped filesystem. A scratch workspace; nothing from the host mounted.
- Resource limits. CPU time, memory, processes, disk and wall-clock.
Resource limits are cheap and catch the most common failure, runaway code:
import resource, subprocess, sys
def limit():
resource.setrlimit(resource.RLIMIT_CPU, (1, 1)) # one CPU second
resource.setrlimit(resource.RLIMIT_AS, (256 * 2**20,) * 2) # 256 MB of memory
proc = subprocess.run([sys.executable, "-c", "while True: pass"],
preexec_fn=limit, capture_output=True, timeout=10)
print(proc.returncode < 0) # => True
The generated infinite loop is killed by the kernel after one second of CPU. Limits like these are a layer inside a sandbox, not a sandbox: on their own they do nothing about files, network or the kernel.
Say it in 30 seconds
"Model-written code is untrusted because its behaviour depends on what the model read. Containers share the host kernel; gVisor answers the code's system calls itself, so far fewer reach the host; microVMs like Firecracker give each run its own kernel behind a hypervisor and start quickly; Wasm grants only explicit capabilities but runs a narrow set of code. I choose by threat and workload, typically gVisor or a microVM per session for multi-tenant code execution, and always add no credentials inside, deny-by-default egress, a scratch filesystem and CPU, memory, process and time limits."
Check yourself
Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.
1What does a container share with the host that a microVM does not?
2Why is Wasm not the default for a general data-analysis agent?
3Name four controls every sandbox needs regardless of the isolation technology.