Sandbox
An isolated environment (a container, a VM, a throwaway checkout) where an agent can run commands without touching anything you care about. Sandboxing is what makes autonomous execution survivable: the worst case is a discarded environment rather than a wrecked machine.
At a glance
- Isolates
- Files, processes, network, credentials
- Lightest
- OS permission profile around the process
- Common
- Docker container
- Stronger
- MicroVM such as Firecracker
- Not the same as
- A git worktree
How it works
Isolation has independent dimensions, and a sandbox is only as strong as the ones it covers. Filesystem: can the agent read your home directory and SSH keys, or only a scratch copy of the repo? Processes: can it see or kill other things on the host? Network: can it reach any host, or only a package registry? Credentials: which environment variables and tokens exist inside it?
Implementations range from an OS-level permission profile around the agent process, through a container, to a lightweight virtual machine, to a remote environment created per task and destroyed afterward. Each step up costs setup time and buys stronger separation from the kernel you depend on. Pick the level from the input, not the agent: trusted code you wrote needs less than a stranger's pull request.
Why it matters
Approving every command keeps you safe and makes you the bottleneck. Letting an agent run unattended is reasonable only when a mistake, or a prompt injection, is contained to something disposable. A sandbox changes the question from "do I trust this command" to "do I mind losing this environment", and the second has an easy answer.
It also makes parallel work practical. Several agents can each run installs, migrations and test suites in their own environment without fighting over ports, databases or global packages, and a run that went badly is cleaned up by deleting the environment rather than by auditing what it changed on your machine.
Sandbox versus worktree
A git worktree gives a task its own checkout and branch so parallel changes do not collide in the same files. It isolates code, not execution: a command run in a worktree still runs as you, on your machine, with your network and credentials. For untrusted input you want both, a separate checkout and a constrained place to run it.
Example
docker run --rm -it \
--network none \
-v "$PWD":/work -w /work \
node:22 bashCommon mistakes
- Mounting the host's
.env, cloud config or a broad GitHub token into the sandbox the agent was meant to be kept from. - Leaving outbound network unrestricted, which turns any compromise into data exfiltration.
- Mounting the Docker socket inside the container, which hands the sandbox control of the host.
In Fredrin
Fredrin runs every ticket in its own branch and real git worktree so parallel agents never overwrite each other. That is file isolation for parallel work, not a sandbox.
Branches and worktreesRelated terms
Frequently asked questions
Is a Docker container a secure sandbox?
It is a reasonable boundary against accidents and weaker against a determined attacker, because it shares the host kernel. A microVM gives stronger isolation for genuinely untrusted code.
Does a sandbox stop prompt injection?
It does not stop the model from being misled, but it limits what a misled agent can reach. Pair it with no mounted secrets and a restricted network.