# Agent Sandbox

> The Agent Sandbox is an isolated environment that limits what an AI agent can access and change.

## How do I sandbox an AI coding agent?

The isolated environment, such as a container or restricted file system and network, where an agent runs commands. Limits possible damage from mistakes or prompt injection while giving the agent more freedom to act.

- Topic: Agentic Coding
- Type: technique

## Example

Wrong:

```bash
docker run -it -v "$HOME":/home/agent agent-image
```

Right:

```bash
docker run -it --rm \
  --network none \
  -v "$PWD":/workspace -w /workspace \
  agent-image
```

Mounting only the project and turning off the network keeps SSH keys and tokens out of reach and blocks data from leaving.

## Common mistakes

- Mounting the whole home folder, giving the agent access to SSH keys and cloud credentials.

## Key points

- The agent can write only inside the project folder, not the home directory or system paths.
- Network access is off or limited to an allowlist of domains.
- No production credentials or personal tokens are available inside the sandbox.

## Interview questions

### Is a container enough to sandbox an AI agent?

It is a good start if it mounts only the project, has no secrets inside and limits the network. Mounting the home folder or the Docker socket removes most of the protection.

### Why does a sandbox matter if I approve every command?

Approvals get tiring and people stop reading them. A sandbox limits the damage when a bad command or a prompt injection slips through.

### Can an agent in a sandbox still install packages?

Yes, if the network allowlist includes the package registry. Keep other domains blocked so injected instructions cannot send data out.

## Related cards

- [Agent Permissions](https://wonderium.dev/ai/agent-permissions.md)
- [Containerization](https://wonderium.dev/engineering/containerization.md)
- [Coding Agent](https://wonderium.dev/ai/coding-agent.md)
- [Prompt Injection](https://wonderium.dev/ai/prompt-injection.md)
- [Background Agent](https://wonderium.dev/ai/background-agent.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/agent-sandbox
- Last updated: 2026-11-25
