Sub topic 1
Why Agents Need a Sandbox: Threats and Goals
Prerequisites
This chapter assumes comfort with the Linux command line, basic Docker usage, Linux file permissions, and the general behavior of an LLM-based coding agent.
Threats and Goals
A coding agent can read files, run commands, install packages, and change source code. A mistaken or manipulated agent might delete data, read private keys, change system settings, or send source code to an external service. A dependency installation or test command can also consume all available CPU, memory, or processes.
A sandbox is an isolation boundary that limits these effects. The goal is least privilege: give the agent only the files, permissions, network access, and resources required for its task.
From Processes to VMs
Isolation has levels. A normal process shares the host kernel and usually has broad access allowed by its user account. A container hides parts of the system with kernel features, but it still shares the host kernel. A user-space kernel such as gVisor adds another system-call boundary. A virtual machine or microVM runs a separate guest kernel, giving stronger separation at higher startup and resource cost.
Container Isolation Primitives
Containers combine several Linux mechanisms:
- Namespaces give a process its own view of processes, mounts, users, and networks.
- Control groups, or cgroups, limit CPU, memory, and process counts.
- Capabilities split powerful root privileges into smaller permissions.
- Seccomp filters system calls that the process may invoke.
These controls reduce risk, but containers are not automatically secure. A privileged container, a host filesystem mount, or an exposed Docker socket can undermine the boundary.
Running a Hardened Agent
Start with a non-root user, a read-only root filesystem, no network, dropped capabilities, and resource limits:
docker run --rm -it \
--user 1000:1000 \
--read-only \
--tmpfs /tmp \
--cap-drop=ALL \
--security-opt no-new-privileges \
--pids-limit 256 \
--memory 2g \
--cpus 2 \
--network none \
-v "$PWD":/workspace \
-w /workspace \
python:3.12-slim bashFilesystem Scope
Mount only the project directory, preferably as read-write when edits are required. Do not mount your home directory, SSH keys, cloud credentials, Docker socket, or the host root filesystem. Use a temporary checkout when possible, then review the changes before copying them back.
Exercise
Why is --network none useful even when the agent only edits local code?
Show answer
It prevents commands or malicious instructions from sending files, credentials, or results to external hosts.