Containers, Sandboxes, AI and everything in between

6 min. read
Illustration of sandboxes and microVMs

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.

Code Snippet

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 but they can be

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.

Now, Sandboxes aren’t very different from containers.

The definition for Sandboxing doesn’t hold any meaning except that it’s more of

a security boundary that restricts what an application can do.

Therefore, If you run your container with limited process capabilities and access to the host machine, it can typically be considered as a sandbox.

With a normal docker container

docker run --rm python:3.12 python app.py

You get:

  • Filesystem isolation.
  • Process namespace isolation.
  • Resource management.
  • Network isolation depending on configuration.
  • Default security restrictions.

But the application still shares the host kernel.

docker run --rm \
  --network none \
  --memory=128m \
  --cpus=0.5 \
  --pids-limit=32 \
  --read-only \
  --cap-drop=ALL \
  --security-opt=no-new-privileges \
  --security-opt seccomp=/path/to/seccomp.json \
  --user 10001:10001 \
  python:3.12 \
  python app.py

Now you've added several restrictions:

  • No network access.
  • 128 MB memory limit.
  • Half a CPU.
  • Maximum 32 processes.
  • Read-only root filesystem.
  • No Linux capabilities.
  • No privilege escalation.
  • Custom syscall restrictions.
  • Non-root execution.

This is a much more hardened container i.e. sandbox.

Let’s look at the distinction:

Technology What it provides
ContainerApplication packaging and process isolation
Linux sandboxRestricted access to system resources
MicroVMHardware-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 a hybrid of it 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.sock

This 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-sbx

Check 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 $USER

Log out and back in, then authenticate:

sbx login

Refer 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-app

Normally, you would start your coding agent directly from this directory.

Instead, let’s launch it inside a sandbox:

sbx run --name node-agent claude

That’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 ls

You can inspect the active sandbox, its agent, status and workspace.

You can also inspect its network rules:

sbx policy ls

For example, if your application needs to download npm packages, you can explicitly allow the npm registry:

sbx policy allow network registry.npmjs.org

This 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-agent

This stops the sandbox but preserves its state.

When you no longer need it:

sbx rm node-agent

This removes the sandbox and its internal filesystem, images, containers and other state.

Your original host project directory remains unaffected by the cleanup.

Secrets

Docker Sandboxes also handle API keys and authentication credentials for sandboxed agents.

You can use the below commands to set, list and remove any secrets used by your agents while never leaving your host system’s OS keychain.

# secret is global by default
sbx secret set anthropic

# scope a secret to a specific sandbox
sbx secret set openai --sandbox my-sandbox

# both commands prompt you for the secret value interactively
sbx secret ls

SCOPE      SERVICE   SECRET
(global)   github    gho_GCaw4o****...****43qy
# Remove a secret
sbx secret rm github

# To remove a sandbox-scoped secret, pass --sandbox
sbx secret rm github --sandbox my-sandbox

The store backing sbx secret set depends on your operating system:

  • macOS: the system Keychain.
  • Windows: the Windows Credential Manager.
  • Linux: the Secret Service exposed by your desktop keyring, such as GNOME Keyring or KDE Wallet.

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 containerisation 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 the same problem in a slightly different way.

So if you don’t want to use docker, some of the other tools that I have used are:

Bubblewrap (bwrap)

GitHub: containers/bubblewrap

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/sh

This 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

Official documentation

Firejail is another Linux sandboxing tool.

It uses namespaces, seccomp-bpf and Linux capabilities to restrict applications.

Its interface is particularly simple:

firejail firefox

You can also create application-specific profiles and restrict filesystem or network access.

For example:

firejail --net=none my-program

Firejail 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.

Special Mentions

We also have other tools to run microVMs and sandbox specific work spaces.

One such fantastic tool that comes to mind was recently launched by CJ from Syntax and is called Devvm.

I haven’t used it myself but as a fan of CJ’s work, I know that the stuff he builts really comes from a place of providing a great Developer Experience to the users.

Cloud Sandboxes

The AI boom has also brought a bunch of new cloud providers into the space. These platforms let us run agents inside isolated cloud microVMs, in fully sand boxed environments that we can provision, spin up, and tear down on demand all through from your application’s code.

Some popular options worth checking out are:

And it's not just the new players offering this. Your favourite cloud providers are getting into the game too.

For example, Cloudflare recently introduced Sandboxes on top of its Workers platform.

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 back end and infrastructure engineering.

Don’t just make your agents capable.
Give them a controlled environment to be capable in.

Until Next Time,

Happy PromptingCoding👋

Further reading & references

  1. Docker: A New Approach for Coding Agent Safety
  2. Docker: Docker Sandboxes — Run Claude Code and Other Coding Agents Unsupervised
  3. Docker Sandboxes — Official Documentation
  4. Docker Sandboxes — Isolation Layers
  5. Bubblewrap — Official GitHub Repository
  6. Firejail — Documentation



Back To Articles