Understanding the Sandbox Environment Explained
Last updated: October 2026
A sandbox is an isolated space where you can run code, apps, or tools without letting them touch the rest of your system. If something inside the sandbox breaks, deletes files, or behaves badly, the damage stays inside. Your laptop, your servers, and your data stay safe.

Sandboxes have been around for decades. Browsers use them. Mobile apps use them. Security teams use them to open suspicious files. But in 2026 the word “sandbox” has a new meaning for most developers: a safe place to run AI coding agents like Claude Code, Codex, Gemini CLI, or Copilot.
This guide explains what a sandbox is, why you need one, why AI agents in particular need one, how a sandbox is different from a container, and how to pick the right sandbox for your work.
Table of contents
- What is a sandbox?
- Types of sandboxes
- Why use a sandbox?
- Why AI agents need a sandbox
- Sandbox vs container: what is the difference?
- What makes a good agent sandbox?
- Sandbox options for AI agents in 2026
- Why Docker Sandboxes fits most developers
- Getting started in 5 minutes
- FAQ
What is a sandbox?
The name comes from a children’s sandbox. Kids can build, dig, and make a mess, but the sand stays inside the box. In computing, a sandbox works the same way.
A sandbox gives a program:
- Its own space to read and write files, usually not your real home folder.
- Limited access to the network, so it can only talk to the places you allow.
- No direct access to your secrets, passwords, or SSH keys.
- A clear boundary, so a crash or a bad command cannot spread to the host machine.
The key idea is simple: assume the code inside might do something wrong, and make sure it does not matter if it does.
Everyday examples of sandboxes
- Web browsers. Each tab runs in a sandbox, so a bad website cannot read files on your computer.
- Mobile apps. iOS and Android keep each app in its own sandbox. An app cannot read another app’s data without permission.
- Malware analysis. Security teams open suspicious files in a sandbox to watch what they do.
- Test environments. Payment providers give developers a “sandbox” account to test with fake money.
- AI agents. Developers run coding agents in a sandbox so the agent can work freely without risking the host.
Types of sandboxes
Not all sandboxes are equally strong. The main difference is where the wall is built.
| Type | How it isolates | Examples | Strength |
|---|---|---|---|
| Process-level | OS rules limit what one process can do | seccomp, Landlock, macOS Seatbelt, bubblewrap | Light, but shares everything with the host kernel |
| Container | Linux namespaces and cgroups | Docker containers, Podman | Good for packaging apps; shares the host kernel |
| User-space kernel | A fake kernel catches system calls | gVisor | Stronger than containers, some app compatibility limits |
| MicroVM | A tiny virtual machine with its own kernel | Firecracker, Kata Containers, Docker Sandboxes | Strong hardware-level boundary, starts fast |
| Full VM | A complete virtual machine | VirtualBox, VMware, cloud VMs | Strong, but heavy and slow to start |
As you go down the table, isolation gets stronger. For a long time the trade-off was speed: strong isolation meant slow, heavy VMs. MicroVMs changed that. They boot in about a second and still give each workload its own kernel.
Why use a sandbox?
You use a sandbox whenever you want to run something you do not fully trust, or something that could make mistakes. Common reasons:
- Safety. A wrong command like
rm -rfonly deletes files inside the sandbox. - Security. Malicious code cannot read your secrets or reach your internal network.
- Clean experiments. Try new tools, packages, or settings without polluting your machine.
- Repeatability. Every run starts from a known state, so results are easier to trust.
- Easy cleanup. When you are done, delete the sandbox. Nothing is left behind.
Why AI agents need a sandbox
A chatbot only writes text. An AI agent takes actions. It runs shell commands, installs packages, edits files, calls APIs, and opens network connections. Modern coding agents can work for hours without a human checking each step.
That is what makes agents useful. It is also what makes them risky.
What can go wrong without a sandbox
- Deleted files. There are many public reports of agents running a cleanup command in the wrong folder and wiping a home directory or a production database.
- Leaked secrets. An agent on your laptop can read
~/.aws,~/.ssh,.envfiles, and browser data. One bad tool call can send them anywhere. - Prompt injection. An agent reads a README, an issue, or a web page that contains hidden instructions. The agent follows them, because it cannot always tell data from commands.
- Supply chain attacks. Agents install packages quickly. A typo-squatted npm or PyPI package can run code the moment it is installed.
- Permission fatigue. Agents ask “Can I run this?” again and again. People get tired and click “allow all”. At that point the safety prompts do nothing.
Why approval prompts are not enough
Most coding agents have a “yolo” or “dangerously skip permissions” mode, because approving every command is slow. A sandbox lets you turn that mode on safely. The agent can do whatever it wants inside the box, and the box decides what reaches the outside world.
In short: you do not need to trust the agent if you trust the sandbox.
What an agent sandbox should control
- Filesystem: the agent sees only the project folder, not your whole disk.
- Network: outbound traffic goes only to allowed hosts, such as your package registry and model API.
- Credentials: API keys are used for the agent but never handed to it in plain text.
- Tools: the agent can still run Docker, build images, and run tests, because that is real development work.
Sandbox vs container: what is the difference?

This is one of the most common questions. Many people think “I already run my agent in a Docker container, so it is sandboxed.” That is only partly true.
A container is a way to package and run an app with its own files and libraries. It uses Linux namespaces and cgroups to keep processes apart. But all containers on a machine share the same host kernel. Containers were designed to ship and run software you trust, not to hold software that might try to escape.
A sandbox is about the security boundary, not the packaging. A good agent sandbox adds layers that a plain container does not have by default.
| Plain container | MicroVM sandbox | |
|---|---|---|
| Main goal | Package and run apps | Contain untrusted or unpredictable code |
| Kernel | Shared with the host | Own kernel per sandbox |
| Kernel bug impact | Can affect the host and other containers | Stays inside the VM |
| Run Docker inside | Needs the host socket or privileged mode (both risky) | Own private Docker daemon |
| Network control | Open by default | Allow-list policy by default |
| Secrets | Passed in as env vars the agent can read | Injected by a proxy outside the sandbox |
| Best for | Services you wrote and trust | AI agents, untrusted code, experiments |
The Docker socket problem
Coding agents often need to build images and run containers. In a normal container, the usual trick is to mount /var/run/docker.sock. That gives the agent control of the host Docker daemon, which is almost the same as root on your machine. A microVM sandbox avoids this by giving each sandbox its own Docker daemon inside the VM.
Bottom line: containers and sandboxes are not enemies. Containers are great for running your apps. For running an agent that writes and executes its own code, you want a stronger wall around it. Many sandboxes, including microVM ones, still use container images inside, so you keep the tools you already know.
What makes a good agent sandbox?
Before you pick a tool, check it against this list:
- Strong isolation. Ideally a separate kernel (microVM or VM), not only namespaces.
- Network policy. Deny by default, allow by host name, and a log of what was blocked.
- Secret handling. Real keys stay outside the sandbox.
- Works with your agent. Claude Code, Codex, Gemini CLI, Copilot, OpenCode, or your own.
- Real dev workflow. Git, package managers, Docker builds, and tests all work.
- Fast startup. Seconds, not minutes. Otherwise people skip it.
- Local and cloud. Run on your laptop while you work, and in the cloud for long or parallel jobs.
- Easy cleanup and low cost. Stop, pause, or delete without fuss.
Sandbox options for AI agents in 2026
There is no single right answer. Here is an honest look at the main approaches.
- Agent built-in sandboxing. Some agents ship their own OS-level sandbox (for example Seatbelt on macOS or bubblewrap on Linux). Easy to turn on, but it shares your kernel and setup differs per agent.
- Plain Docker containers or dev containers. Familiar and free. Fine for low-risk work, but you have to add network rules and secret handling yourself, and Docker-in-Docker gets tricky.
- Hosted sandbox APIs such as E2B, Daytona, Modal, and similar. Great if you are building a product that runs agent code at scale through an SDK. They run in the vendor’s cloud, not on your laptop.
- Kubernetes-native sandboxes such as gVisor or Kata Containers on a cluster. A good fit for platform teams that already run Kubernetes.
- Docker Sandboxes (sbx). MicroVM sandboxes built for coding agents, with one CLI for local and cloud. More on this below.
Why Docker Sandboxes fits most developers

If you are a developer who wants to run a coding agent on your own projects, Docker Sandboxes ticks most boxes on the checklist above. Here is why, in plain terms.
1. A real microVM, not just a container
Each sandbox runs in its own microVM with its own kernel. Docker’s docs describe the isolation as “Full (hypervisor)”. If the agent breaks something, it breaks the VM, not your laptop.
2. Its own Docker daemon inside
Each sandbox has a private Docker daemon, image cache, and packages. The agent can run docker build and docker compose up without ever touching your host Docker socket.
3. Secrets the agent never sees
The agent only sees a placeholder value instead of the real API key. A proxy on the host swaps in the real key after the request leaves the microVM. So even if the agent is tricked by a prompt injection, it has no real key to leak.
4. Network policy by default
All outbound traffic goes through a host-side proxy that enforces your rules. On first run you pick a default policy: Open, Balanced, or Locked Down. You can then allow specific hosts, for example:
sbx policy allow network registry.npmjs.org
5. Works with the agents you already use
Supported agents include Claude Code, Codex, Copilot, Cursor, Gemini, Kiro, OpenCode, Droid, Devin, Docker Agent, and a plain shell. Claude Code users with a Claude subscription can sign in with /login inside the sandbox.
6. Your project, not your whole disk
You choose what the agent sees. Mount just your project folder, use a “clone mode” where the agent works on a private Git clone, or start with no host files at all.
7. Local and cloud with one CLI
Local sandboxes run on your laptop. Cloud Sandboxes run the same microVM model on Docker-managed machines, for long or parallel jobs. You can even move a running sandbox between them:
sbx move my-project --to cloud
A common pattern: try an idea locally, then send the long task to the cloud before you log off, and review the result the next morning.
8. Kits for repeatable setups
Kits package an agent plus its tools, settings, and guardrails into a reusable sandbox. The community is building kits for databases, observability tools, and security scanners. See awesome-docker-sbx for a curated list.
9. Free to start
The sbx CLI and local sandboxes are free, including for commercial work, and do not need Docker Desktop. Cloud Sandboxes are pay-as-you-go, billed per second, and a paused sandbox costs nothing.
When you may not need it
To be fair: if you only use an agent for chat or code suggestions, or you run a single short task you watch line by line, a sandbox may be more than you need. And if you are building a SaaS product that spins up thousands of sandboxes through an API, a hosted sandbox SDK might fit better. For day-to-day coding with agents that run commands on their own, a microVM sandbox is the safer default.
Getting started in 5 minutes
On macOS with Homebrew (see the official install guide for other platforms):
brew install docker/tap/sbx
sbx login
cd ~/my-project
sbx run --name my-sandbox claude # start Claude Code in a sandbox
sbx ls # list sandboxes
sbx policy ls # see network rules
sbx stop my-sandbox # pause, keeps state
sbx rm my-sandbox # delete everything
To run the same agent in the cloud instead:
sbx --cloud run claude
Want hands-on labs? Join the Collabnix community on Slack and Discord, where members share sandbox kits, workshop labs, and real-world setups.
FAQ
What is a sandbox in simple words?
A sandbox is a closed, safe space where a program can run without affecting the rest of your computer. If the program misbehaves, only the sandbox is affected.
What is an AI agent sandbox?
It is an isolated environment where an AI agent can run commands, install packages, and edit code, while its access to your files, network, and secrets is limited and controlled.
Is a Docker container a sandbox?
A container gives some isolation, but it shares the host kernel and is open to the network by default. It is a good packaging tool, but on its own it is a weak sandbox for untrusted or AI-generated code.
What is the difference between a sandbox and a virtual machine?
A VM is one way to build a sandbox. “Sandbox” describes the goal (contain the code). A VM, microVM, or container describes the technology. MicroVMs give VM-level isolation with near-container speed.
What is a microVM?
A microVM is a small, stripped-down virtual machine that boots in about a second. It has its own kernel, so it gives stronger isolation than a container while still being light.
Do I need a sandbox to use Claude Code or Codex?
You do not have to, but it is strongly recommended if you let the agent run commands without approving each one. A sandbox lets you use auto-approve modes safely.
Are Docker Sandboxes free?
Local Docker Sandboxes and the sbx CLI are free, including for commercial use. Cloud Sandboxes are billed per second of compute. Model API costs are separate.
Do Docker Sandboxes need Docker Desktop?
No. The sbx CLI is a standalone tool and does not need Docker Desktop.