A coding agent that runs `exec()` on model-generated Python directly inside the same process serving user requests has handed an attacker who successfully manipulates that agent the same privileges the entire application runs with — the same filesystem access, the same network access, the same environment variables holding production credentials. Every guardrail built in this course up to this point tries to prevent a malicious or hallucinated instruction from reaching code execution in the first place; sandboxing is the layer that assumes, correctly, that eventually one will get through anyway, and asks what the blast radius is once it does.
A sandbox is an execution environment deliberately stripped of everything the code running inside it does not need: no access to the host filesystem beyond an explicitly mounted, isolated directory, no network access unless explicitly granted, no ability to see or affect other processes on the host, and a hard ceiling on CPU, memory, and wall-clock time so a runaway or deliberately resource-exhausting script cannot take down anything beyond its own container. This is least privilege from the previous lesson applied specifically to the one capability that is hardest to bound after the fact — arbitrary code execution — because unlike a scoped API token, a line of running code can attempt literally anything the underlying operating system permits unless something outside the process itself prevents it.
This lesson builds the actual containment primitives a platform engineer would reach for — namespaces and seccomp for process- and syscall-level isolation, gVisor-class sandboxes for a stronger boundary than a container alone provides, read-only mounts, dropped Linux capabilities, and no-network-by-default — not as abstract security theory but as the specific mechanisms that make "the agent's code ran, and it could not have done anything beyond what we explicitly allowed" an engineering guarantee rather than a hope.