Sub topic 7
Sandboxing: limits the agent cannot talk its way past
This chapter assumes you know the allow, ask, and deny decision from the permission model, and that you have seen how pattern rules can be bypassed.
Prompts decide, sandboxes enforce
A permission prompt is a policy check inside the agent program. The agent asks, you answer, and the tool runs. If the check has a bug, if a rule is too broad, or if you approve something you misread, nothing else stops the action.
A sandbox is a boundary enforced by the operating system or a container runtime. A process inside it cannot read, write, or connect outside the limits, no matter what the model says or what you approved. The agent cannot talk its way past the boundary, because the boundary does not read text.
You need both. Prompts handle intent: "should this action happen?" Sandboxes handle damage: "if it goes wrong, how bad can it get?"
What a sandbox limits
Most sandboxes restrict three things.
| Limit | Typical setting | What it prevents |
|---|---|---|
| Filesystem | Write only to the project directory and a temp directory | Editing shell profiles, SSH keys, or other projects |
| Network | No access, or an allowlist of hosts | Sending code or secrets to an unknown server |
| Processes and resources | No privileged operations, CPU and memory caps | Installing system services, runaway jobs |
Common mechanisms are containers, virtual machines, and OS features such as macOS Seatbelt or Linux namespaces and Landlock. A dev container, or a throwaway cloud workspace, is a practical choice that needs no special agent support.
Why path checks are not enough
The earlier example resolved a path before testing it. That is a good check, but it runs in the same program the model is steering. A sandbox applies the same idea one level down. Even if the agent runs python -c "open('/home/me/.ssh/id_rsa')", which no command pattern anticipated, the operating system refuses the read.
A concrete example with Docker runs the agent's shell commands with no network and only the project mounted:
docker run --rm -it \
--network none \
--read-only \
--tmpfs /tmp \
-v "$PWD":/workspace \
-w /workspace \
python:3.12-slim bashInside this shell, curl https://example.com fails because there is no network. Writes outside /workspace and /tmp fail because the root filesystem is read-only. Your home directory and its credentials are not mounted, so they do not exist from the agent's point of view.
Gotchas
- Mounted secrets. Mounting your home directory,
~/.aws, or a Docker socket into the sandbox gives the agent those credentials or full control of the host. Mount only what the task needs. - Writable project directory. The agent can still change anything in the project, including git hooks and CI files. Review diffs afterward.
- Network allowlists. A broad allowlist, such as a hosting site that anyone can upload to, still permits exfiltration.
- Weak isolation. A normal container shares the host kernel. For untrusted code, a VM or a stronger runtime gives better isolation.
- Friction. Strict limits make installs and tests fail. Open the narrowest hole that fixes the failure, rather than turning the sandbox off.
Exercise
An agent has a deny rule for curl *, and it runs in a container with --network none. The model runs python -c "import urllib.request; urllib.request.urlopen('https://evil.example')". What happens, and which control stops it?
Show answer
The command matches no deny pattern, so the permission check may allow or ask depending on your rules. The request still fails, because the container has no network, and the sandbox is the control that stops it. This shows why pattern rules alone are incomplete and why enforcement needs to sit below the agent.
Exercise
You mount your whole home directory into a sandbox so the agent can "find config files." Name one risk this creates and a safer alternative.
Show answer
The agent can read and possibly modify credentials such as ~/.ssh and ~/.aws, so a prompt injection could leak them. Mount only the project directory, and copy in any specific config file the task needs.