
AI coding agents are getting really good at executing tasks independently.
They can steal you environment variables read your codebase, install dependencies, execute shell commands, run tests, modify files and even start Docker containers.
But there is a problem, a big one actually.
Would you give an AI agent unrestricted access to your machine and trust that it will always do the right thing?
I wouldn’t.

This is where Sandboxing becomes interesting.
Let’s understand what sandboxes are, how they work, and actually run an AI coding agent inside one.
Containers are not sandboxes
We have been using containers for years. They provide process isolation, file system isolation and resource control using Linux namespaces and cgroups.
However, containers share the host’s Linux kernel.
That means a container is not automatically a strong security boundary, especially when you’re running untrusted code or giving an autonomous agent access to the environment.
Let’s look at the distinction:
| Technology | What it provides |
|---|---|
| Container | Application packaging and process isolation |
| Linux sandbox | Restricted access to system resources |
| MicroVM | Hardware-assisted isolation with its own kernel |
A container answers: Where should my application run?
A sandbox answers: What is this application allowed to access?
And a microVM adds another layer by giving the workload its own kernel.
Meet Docker Sandboxes
Basically the Docker team came full circle from moving away from microVMs to containers to just building one themselves when they introduced Docker Sandboxes specifically for running AI coding agents in isolated environments.
Each sandbox runs inside a lightweight microVM with:
- Its own Linux kernel.
- Its own filesystem.
- Its own Docker Engine.
- Its own network environment.
- Controlled access to host files and credentials.
Why does the separate Docker Engine matter?
Consider a typical approach where you run an AI agent inside a container and mount the host Docker socket:
-v /var/run/docker.sock:/var/run/docker.sockThis is convenient, but it also gives the agent access to your host Docker daemon.
An agent that can control your Docker daemon can potentially gain access to much more than the project it was supposed to work on.
Docker Sandboxes solve this differently. The agent gets its own Docker Engine inside the microVM.
It can build images, start containers and run Docker Compose without controlling the host Docker daemon.
That’s a meaningful architectural difference.
Let’s run our first Sandbox
For this tutorial, let’s assume:
- Ubuntu 24.04 or later.
- A 64-bit machine with KVM support.
- Claude Code installed through Docker’s supported agent workflow.
- An existing Node.js project.
Docker Sandboxes also supports macOS and Windows, but the installation requirements differ.
Step 1: Install Docker Sandboxes
Docker provides a standalone sbx CLI. You don’t need Docker Desktop or a host Docker Engine just to use the CLI.
For Ubuntu, you can install only the sandbox package:
curl -fsSL https://get.docker.com | sudo REPO_ONLY=1 sh
sudo apt install docker-sbxCheck that KVM is available by running:
lsmod | grep kvm
Your output should contain something like kvm_intel or kvm_amd
For local Linux sandboxes, your account also needs access to KVM:
sudo usermod -aG kvm $USERLog out and back in, then authenticate:
sbx loginRefer to Docker’s installation guide for other operating systems and prerequisites.
Step 2: Navigate to your project
Let’s use a Node.js application as an example.
cd ~/projects/my-node-appNormally, you would start your coding agent directly from this directory.
Instead, let’s launch it inside a sandbox:
sbx run --name node-agent claudeThat’s it.
Your agent is now running inside a Docker Sandbox.
The first execution might take longer because Docker needs to pull the agent image. Subsequent executions can reuse cached images.
If this is your first run, Docker may ask you to select a network policy.
Choose Balanced for this tutorial.
Step 3: Give the agent some work
Try something simple:
Inspect this Node.js project.
Install the required dependencies,
run the existing tests, identify any failures,
and fix them.
Do not modify files outside the project.The agent can now execute commands, install packages and run containers inside its isolated environment.
One important detail: when you run sbx run from a project directory, that directory is mounted read-write into the sandbox by default.
So the agent can modify your actual project files.
The rest of the host filesystem remains outside its normal sandbox access.
If you want the agent to work on a private copy instead, use Docker’s clone workflow.
Step 4: Inspect your running sandboxes
Open another terminal:
sbx lsYou can inspect the active sandbox, its agent, status and workspace.
You can also inspect its network rules:
sbx policy lsFor example, if your application needs to download npm packages, you can explicitly allow the npm registry:
sbx policy allow network registry.npmjs.orgThis is an important part of sandboxing.
Filesystem isolation alone isn’t enough. An agent with unrestricted network access can still communicate with external services, download malicious dependencies or send data outside your environment.
Control both.
Step 5: Clean up
Once you’re done:
sbx stop node-agentThis stops the sandbox but preserves its state.
When you no longer need it:
sbx rm node-agentThis removes the sandbox and its internal filesystem, images, containers and other state.
Your original host project directory remains unaffected by the cleanup.
You see?
The commands are the same as managing a container.
That’s the beauty of disposable execution environments.
What’s happening under the hood?
Let’s simplify the architecture.
Developer
|
v
AI Agent
|
v
Docker Sandbox
|
------------------------
| |
v v
MicroVM Network Proxy
| |
v v
Private Docker Network Rules
Engine |
| v
v Internet
Containers
|
v
Test / Build
---------------------------
HOST MACHINE
---------------------------
Host Docker Engine
Credentials
Other Files
Operating System
There are a few important boundaries here:
Hypervisor isolation: Each sandbox has its own Linux kernel. This is different from ordinary containers that share the host kernel.
Network isolation: Outbound traffic is routed through a policy-controlled proxy. Destinations can be allowed or blocked.
Docker Engine isolation: The agent communicates with its private Docker Engine rather than the host daemon.
Credential isolation: Docker provides a credential proxy mechanism so supported agent credentials can remain outside the microVM.
One caveat: explicitly shared workspaces and other configured integrations still expose the resources you grant them. A sandbox is only as restrictive as its configuration and security boundaries.
What about Other tools?
Now just as for their containerization service which is built on the Open Container Initiative and have other players in the space like Podman and Apple containers (yeah, they have one too).
Docker isn’t the first company or project to work on sandboxing.
There are several interesting alternatives, each solving a slightly different problem.
Some of the ones that I have used are:
Bubblewrap (bwrap)
Bubblewrap is a lightweight Linux sandboxing tool that uses namespaces to construct isolated environments.
You can control which directories are visible, create separate PID and network namespaces, and apply additional restrictions.
Example:
bwrap \
--ro-bind /usr /usr \
--ro-bind /bin /bin \
--proc /proc \
--dev /dev \
--tmpfs /tmp \
--unshare-net \
/bin/shThis is a minimal illustration, not a complete production security profile. Real applications need additional filesystem and runtime dependencies.
Bubblewrap is useful when you want low-level control over process isolation without introducing a full VM.
Firejail
Firejail is another Linux sandboxing tool.
It uses namespaces, seccomp-bpf and Linux capabilities to restrict applications.
Its interface is particularly simple:
firejail firefoxYou can also create application-specific profiles and restrict filesystem or network access.
For example:
firejail --net=none my-programFirejail is particularly useful for sandboxing desktop applications and individual processes.
I also found a great practical guide on how to use these sandboxing tools with popular AI Agent harnesses like Opencode, Claude, Pi etc.
You can look at the agent sandboxing guidelines of Odoo which is one of the largest open-source python codebases.
So, Which one should you use?
If you’re building an AI agent that needs to execute arbitrary commands, install packages, build containers and run tests, Docker Sandboxes are an interesting starting point.
If you’re building your own execution infrastructure, understanding tools like Bubblewrap will give you a much better understanding of the underlying security trade-offs.
Takeaway
The way we build software is changing.
Earlier, we mostly worried about where our application would run, how it would scale and how we would deploy it.
Now, we’re also building systems that allow software to make decisions and execute actions independently.
That introduces a different security problem.
We shouldn’t have to trust every command an AI agent or the company who made it generates.
We should be able to control what happens when that command executes.
These giants have already leached off on open-source (and closed) IP enough to take away our jobs.
The least we can do is make sure they don’t have our credentials too (I mean whatever is left of it)
Containers made application packaging easier. Sandboxes make controlled execution possible.
And as AI agents become more autonomous, I think understanding both will become an essential part of backend and infrastructure engineering.
Don’t just make your agents capable.
Give them a controlled environment to be capable in.
Until Next Time,
Happy DebuggingPrompting👋
Further reading & references
- Docker: A New Approach for Coding Agent Safety
- Docker: Docker Sandboxes — Run Claude Code and Other Coding Agents Unsupervised
- Docker Sandboxes — Official Documentation
- Docker Sandboxes — Isolation Layers
- Bubblewrap — Official GitHub Repository
- Firejail — Documentation