Topic 5 of 5 · 4 min read
Sandbox escapes and leaky mounts
Goal: Spot the configuration mistakes that let a sandboxed agent reach host secrets or the open network.
Most real sandbox failures are not clever exploits; they are settings that hand the agent a door, such as a mounted Docker socket, a shared home folder or host networking.
Check yourself · 1 of 3
Why is mounting /var/run/docker.sock into an agent container dangerous?
Why it matters
A sandbox is only as strong as the weakest thing placed inside it. Teams build a careful boundary, then add one mount or flag to fix an error. That single choice can give the agent your keys, or full control of the host, and nobody notices because the agent keeps working.
The usual doors
- Docker socket mounted (
/var/run/docker.sock). Whoever can talk to the Docker daemon can start a new container with the host's root folder mounted. That is control of the host. - Home directory or SSH keys mounted. The agent can read
~/.ssh, cloud credentials, shell history and browser data, then use them from inside the box. - .env files and tokens in the workspace. A project folder often holds database passwords and API keys. The agent reads them like any file, and they can end up in prompts and logs.
--privileged. Gives the container broad access to host devices and most capabilities.--network host. Removes network isolation: the container sees the host's interfaces and local services, including ones bound to localhost.- Writable config the sandbox trusts. If the agent can edit the file that defines its own limits, it can loosen them.
- Credentials in the environment. A forwarded SSH agent or a cloud role gives the sandbox the same power you have.
How to review
For any sandbox, list: every mount and its mode, the user, the capabilities, the network mode, the environment variables passed and the credentials reachable. For each, ask: "If the agent was fully hostile, what could it do with this?" Remove or narrow anything that gives more than the task requires.
Before and after
# Weak
docker run -v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.ssh:/root/.ssh --network host agent-image
This hands over the daemon, the keys and the host network in one line. The fix is to remove all three and, if the agent needs a git remote, use a deploy token limited to one repository.
What goes wrong
- "Temporary" flags that stay for months.
- Secrets in the repo folder, so a narrow mount still exposes them.
- No test. Nobody tries to escape, so nobody learns it works.
- Trusting one layer. Keep file limits, network limits and narrow credentials together.
Examples
Reading a run command
docker run --privileged --network host -v ~:/work agent-image
Three issues in one line: privileged mode, host networking and the home folder mounted. Remove each, then mount only the project and allow the network through a proxy.
A safer git setup
Instead of mounting ~/.ssh, create a deploy token that can push to one repository and expires in a day. If the sandbox leaks it, the damage is one repository for a short time.
Key points
- A mounted Docker socket is effectively root on the host.
- Mounting home folders, SSH keys or .env files gives a sandboxed agent your real credentials.
- --privileged and --network host remove isolation that the rest of the setup relies on.
- Review every mount, flag, environment variable and reachable credential by asking what a hostile agent could do with it.
- Give the agent narrow, short-lived tokens instead of your own keys.
Common mistakes
- Mounting the Docker socket so the agent can run builds.
- Leaving .env files and keys in the folder the agent can read.
- Adding --privileged or --network host as a quick fix and keeping it.
- Never testing whether a hostile agent could actually escape.
Check yourself · 2 of 3
What does --network host do to a container?
Check yourself · 3 of 3
The agent only needs to push to one git repository. What is the safest credential?
Practice items, not counted towards your mastery.
Start here
- Sandboxing (Claude Code docs) (opens in a new tab)DocsFree
How a coding agent's sandbox limits files and network, and how it pairs with permission prompts.
- Making Claude Code more secure and autonomous with sandboxing (Anthropic) (opens in a new tab)ArticleFree
Why filesystem and network isolation must work together, explained by the team that built it.
- Docker Engine security (opens in a new tab)DocsFree
What containers isolate, what they share with the host, and how capabilities and the daemon socket matter.
More for this topic
- bubblewrap (opens in a new tab)ToolFree
The unprivileged Linux sandboxing tool that agent CLIs build on.
- OWASP Top 10 for LLM Applications (opens in a new tab)StandardFree
Names excessive agency and insecure output handling, the risks a sandbox contains.