Sub topic 15
What sandboxing does not protect against
This chapter assumes you can run a hardened container (non-root, read-only root, no capabilities, limited network) and know the threat model from earlier chapters. A sandbox limits what a process can reach. It does not decide whether the process should do what it does inside that boundary.
The boundary protects the host, not the project
You must give the agent a writable project directory, so anything the agent can do to that directory, it can do inside the sandbox. This includes:
- Deleting or corrupting source files.
- Adding a backdoor to a dependency list or build script.
- Editing
.git/hooks, CI workflows,Makefiletargets, orpackage.jsonscripts.
None of these escape the container. They only matter when you later run the code on your own machine, commit it, or let CI execute it. The sandbox has moved the danger from "now" to "when you run the output".
Residual risks
| Risk | Why the sandbox does not stop it | Mitigation |
|---|---|---|
| Poisoned output | Changes are written to an allowed mount | Review diffs before running or committing |
| Prompt injection | The agent is manipulated using its own legitimate permissions | Least privilege, approval for risky actions |
| Exfiltration through allowed channels | Any permitted endpoint, including DNS or an API, can carry data out | Narrow egress allowlists, keep secrets out |
| Secrets you passed in | Anything inside the sandbox is readable by the agent | Short-lived, scoped credentials |
| Kernel or runtime escape | Containers share the host kernel, and kernels have bugs | Keep the host patched, use gVisor or a microVM |
| Misconfiguration | `--privileged`, a mounted `/var/run/docker.sock`, or a broad bind mount removes the boundary | Review run flags, avoid those options |
| Approval fatigue | People click "yes" to repeated prompts | Fewer, clearer prompts, safe defaults |
Mounting the Docker socket deserves special attention. Whoever controls it can start a new container with the host's root filesystem mounted, so it is equivalent to root on the host.
Isolation strength has a ceiling
A hardened container reduces the attack surface but still shares one kernel with the host. gVisor shrinks the kernel surface the agent can call. A microVM places a hypervisor between the agent and the host. Each step is stronger, but none is absolute. Hypervisors and runtimes have had escape vulnerabilities, and side channels between co-located workloads exist. Treat isolation as risk reduction that must be kept up to date.
Review before you trust
A practical habit is to inspect what changed, including files outside normal source code, before running anything on the host:
git status --short
git diff --stat
ls -l .git/hooks | grep -v '\.sample$'
git config --local --listThe last two commands show hooks and repository settings that could run code on your machine the next time you use git.
Decision criteria
Ask three questions for each task:
- What is the worst thing the agent could do with the access it has, not the access it lacks?
- Which outputs will later run in a trusted place?
- Which data in the sandbox would hurt you if it leaked?
If an answer is alarming, remove the access, shorten the credential's lifetime, or add a human checkpoint.
Exercise
An agent runs in a container with no network and a read-only root filesystem. It edits .github/workflows/ci.yml in the mounted project to send repository secrets to a remote URL. Which boundary failed, and what should have caught it?
Show answer
No boundary failed. The container worked as designed, because the edit stayed inside the allowed mount. The risk appears when CI runs the modified workflow with real secrets. A human review of the diff, with attention to CI and build files, should catch it. Protected branches that require review for workflow changes add a second check.