跪拜 Guibai
← Back to the summary

A Sandbox Isn't a VM or Docker — It's a Security Boundary, and AI Agents Are Making It Urgent Again


theme: awesome-green

Recently, while reading OpenClaw's documentation, I came across a term: Sandbox.

The documentation mentioned that when an AI Agent executes code, that code can be run inside a Sandbox to restrict the files, processes, and network it can access.

My previous understanding of a Sandbox was simple:

Isn't a Sandbox just a virtual environment?

After some deeper research, I realized that understanding is not accurate. A Sandbox is not the same concept as a virtual machine, Docker, or Python's venv. If I had to explain a Sandbox in one sentence, I now think this is better:

A Sandbox is an artificially designated, restricted area for code execution. The program can run normally, but what it can do is controlled within a defined scope.

Understanding this sentence means understanding the core of a Sandbox.

1. Let's start with an example from daily life

Suppose one day, you hire a repairman to fix a faucet in your home. The simplest approach is to give him the key to your front door directly. This way, he can certainly walk into the kitchen and fix the faucet. But at the same time, theoretically, he could also:

Enter the bedroom
Open your drawers
Look through documents
Take valuables
Even move furniture out

Where does the problem lie? It's not that the repairman lacks the ability to fix the faucet, but rather:

To complete a very small task, we gave him excessive permissions.

Is there a safer and more reliable approach? Yes, there is. We can prepare a dedicated work area and place only the broken faucet and the necessary tools inside:

My Home
┌───────────────────────────────┐
│                               │
│  Bedroom        Private Files │
│                               │
│  Safe           Computer      │
│                               │
│       ┌────────────────┐      │
│       │   Work Area    │      │
│       │                │      │
│       │   Faucet       │      │
│       │   Wrench       │      │
│       │   Screwdriver  │      │
│       │                │      │
│       │   Repairman    │      │
│       └────────────────┘      │
│                               │
└───────────────────────────────┘

The repairman can still work, but the things he can access are now fewer. This is the core idea of a Sandbox:

It's not about preventing the program from running, but about limiting the scope of what the program can affect.

This is also why it's called a Sandbox.

You can imagine it like a sandbox for children to play in. A child can still dig holes, build castles, and make a mess with the sand, but it's best if these activities happen inside the sandbox, rather than all over the living room.

2. A Sandbox is not a "virtual environment"

A common misunderstanding arises here. Some people, upon first encountering the term Sandbox, interpret it as:

Sandbox = Virtual Environment

This is actually not accurate. A more precise relationship would be:

                 Sandbox
                    │
          A security objective
                    │
        ┌───────────┼───────────┐
        ↓           ↓           ↓
     Container      VM        OS Security Mechanisms
     Docker       Virtual      Namespace
                  Machine      seccomp
                               Permission Control

A Sandbox describes "I want to restrict what this program can do."

As for how to achieve it, there are many methods. For example:

All of these can be part of implementing a Sandbox. Therefore:

Sandbox ≠ Docker
Sandbox ≠ Virtual Machine

Docker can be used to implement a Sandbox, and a virtual machine can also be used to implement a Sandbox. Even an ordinary process, if the operating system imposes strict permission controls on it, can become a kind of Sandbox.

So, a Sandbox is more like a security model, rather than a specific technology.

2.1 Is the understanding "A Sandbox is a real environment, just with a limited scope" correct?

This understanding is quite close, but it's best to refine it further: Some Sandboxes indeed run directly on a real operating system, just subject to permission restrictions.

For example:

Real Linux
│
├── Chrome
├── VS Code
├── MySQL
│
└── Restricted Process
      ↑
    Sandbox

However, some other Sandboxes use containers or even virtual machines:

Real Machine
   │
   ↓
Virtual Machine
   │
   ↓
Container
   │
   ↓
Restricted Program

So, the key to judging whether something is a Sandbox is not to ask:

"Is it a real environment?"

But rather to ask:

"Is this program's capability restricted within a boundary?"

This is the essence of a Sandbox.

3. What exactly does a Sandbox restrict?

If you see a system claiming to support Sandboxing in the future, you can first ask it four questions:

How much of the file system can it see?
How many processes can it see?
Where can the network access?
How extensive are the system permissions?

This will basically allow you to judge what this Sandbox actually does.

3.1 File System

Suppose my computer has these items:

/home/me/
│
├── project/
├── Documents/
├── Pictures/
└── .ssh/
      └── id_rsa

I now need a program to modify:

project/

The most dangerous approach is:

Program
  ↓
Entire /home/me

This way, it could theoretically modify the project and also read:

Documents
Pictures
.ssh/id_rsa

A Sandbox can expose only this specific project directory:

Real Computer

/home/me/
│
├── Documents        ← Cannot see
├── Pictures         ← Cannot see
├── .ssh             ← Cannot see
│
└── project
       │
       │ Mapping
       ↓
┌────────────────────┐
│ Sandbox            │
│                    │
│ /workspace         │
│                    │
└────────────────────┘

Thus, the world the program sees might only be:

/workspace

There is an interesting point here. For a program inside a Sandbox, it's not necessarily:

"I know .ssh exists, but I don't have permission to read it."

Sometimes it's even:

"In my world, this directory simply does not exist."

It sees a tailored view of the file system. This is also one of the meanings of "isolation."

3.2 Processes

Another example: your computer is running:

Chrome
VS Code
MySQL
Redis
Node.js

A program running directly on the host machine executes:

ps aux

It might see a large number of system processes. If permissions are sufficient, it might even affect these processes. But after entering a Sandbox, what it sees might become:

Sandbox
│
├── bash
├── node
└── npm

It doesn't even know that Chrome and MySQL exist outside. This is process isolation.

3.3 Network

A Sandbox can also restrict the network.

For example:

Sandbox
   │
   ├──── example.com      ✅
   │
   ├──── api.xxx.com      ✅
   │
   └──── Other Internet    ❌

It can even directly:

Sandbox
   │
   X
Internet

Completely prohibit network access. This is especially important when running untrusted code. Suppose a program accidentally reads an API Key:

sk-xxxxxxxx

An attacker would also want to send it out:

Read Key
   ↓
Connect to Network
   ↓
Upload to Server

If the file permission step didn't block it, the network restriction can still stop the subsequent step. Security systems often don't rely on a single door, but on many doors.

3.4 System Permissions

Finally, there is an even more fundamental question:

Even inside a Sandbox, what capabilities of the operating system can the program invoke?

Many operations of Linux programs ultimately go through system calls:

Application
   ↓
System Call
   ↓
Linux Kernel
   ↓
Disk / Network / Process / Memory

A Sandbox can further restrict these capabilities. For example, restricting:

Mounting file systems
Modifying system time
Loading kernel modules
Accessing certain devices
Creating special network sockets
Operating on other processes

Common mechanisms like capabilities and seccomp inside Docker are precisely for further tightening permissions at this layer. Thus, a relatively complete Sandbox might be:

              Program
                │
                ↓
        ┌───────────────┐
        │   Sandbox     │
        │               │
        │ File Limits   │
        │ Process Limits│
        │ Network Limits│
        │ Permission Limits│
        │ Syscall Limits│
        └───────────────┘
                │
                ↓
          Operating System

Now, looking back at the term "Sandbox," you'll find it describes essentially: A security boundary.

4. What is the relationship between Sandbox, Docker, and Virtual Machines?

These three concepts often appear together, so they are easily confused. We can make a simple comparison.

Concept Main Problem Solved
Sandbox Restricts what a piece of code can do
Docker Container Isolates the running environment of a program
Virtual Machine Virtualizes a complete computer
Python venv Isolates Python packages and dependencies

Among these, the most easily confused are Docker and virtual machines.

Docker

On Linux, a Docker Container typically still shares the Linux Kernel with the host machine. It can be roughly understood as:

Application A     Application B
      │                 │
┌───────────┐      ┌───────────┐
│Container A│      │Container B│
└───────────┘      └───────────┘
        \             /
         \           /
          Linux Kernel
               │
            Hardware

Linux uses mechanisms like Namespaces to make different Containers see different:

Processes
Network
File system mounts
Hostname
Users

Docker's official documentation refers to Namespaces as the most direct layer of isolation for containers. That is to say, a program inside a container might feel:

"This is my Linux."

In reality, it only sees a partial view of the operating system specifically prepared for it.

Virtual Machine

A virtual machine is more thorough; it can even have its own Kernel:

┌──────────────────┐
│ Virtual Machine  │
│                  │
│ Application      │
│       ↓          │
│ Guest OS         │
│       ↓          │
│ Guest Kernel     │
└──────────────────┘
         ↓
     Hypervisor
         ↓
      Hardware

Therefore, a virtual machine usually has a more complete isolation boundary than a typical container, but the cost is also higher. However, one point needs special attention.

Virtualization itself does not equal security.

A system using a virtual machine does not inherently mean it is a well-designed Sandbox. Conversely, a Sandbox absolutely does not require the use of a virtual machine. So, the point remains:

Sandbox describes the objective, while Container and VM describe more about the implementation method.

5. Why is Sandbox being discussed frequently again in the AI Agent era?

Sandbox is actually a very old concept, but it has suddenly become more important in the AI Agent era. The reason is simple: previously, large models typically worked like this:

You ask ChatGPT
      ↓
ChatGPT tells you a command
      ↓
You take a look
      ↓
You decide whether to execute it

For example, ChatGPT tells you:

rm test.txt

The person who finally presses the Enter key is still you. But a Coding Agent is different. The current process is increasingly approaching:

User
 ↓
AI Agent
 ↓
Analyze code
 ↓
Read files
 ↓
Execute shell
 ↓
Modify code
 ↓
Run tests
 ↓
Read results
 ↓
Continue modifying

AI has gradually changed from:

"Giving you suggestions"

to:

"Acting on your behalf"

That is, from previously only having a brain to think and give you ideas, it has now started to grow hands and feet and can do work for you. Thus, a new problem emerges:

Exactly how much permission should we give to AI?

This is why Sandbox has become important again.

Let me give an example I recently saw from OpenClaw: OpenClaw can let an AI Agent execute:

read
write
edit
exec
process

these tools.

Without isolation, command execution could ultimately happen on the host environment where the Gateway is located. After enabling the Sandbox, tool execution can be moved to a sandbox backend. It can use Docker to do this by default. The execution path can be roughly understood as:

AI Agent
    │
    │ I want to execute npm test
    ↓
OpenClaw
    │
    ↓
Sandbox
    │
    ↓
Docker Container
    │
    ↓
npm test

Instead of:

AI Agent
    │
    ↓
My Real Computer
    │
    ↓
npm test

OpenClaw can even, by default, make the Docker Sandbox:

Unable to access the external network
Root file system read-only
Remove Linux capabilities

These specific configurations are not the focus of this article. What is truly noteworthy is the design philosophy behind it:

An Agent can gain the ability to execute code, but this ability should have boundaries.

This is precisely the problem a Sandbox aims to solve.

6. Actually, we use Sandboxes every day

Seeing this, a Sandbox might still seem a bit unfamiliar. Actually, we use them every day. The most typical example is:

The browser.

Suppose you open an unfamiliar website:

https://example.com

The JavaScript inside can:

document.querySelector('#app')

fetch('/api')

localStorage.getItem('user')

But you would absolutely not want a webpage to casually:

Read ~/.ssh/id_rsa

Scan the entire hard drive

Start a shell

Kill VS Code

Delete Documents

Read the memory of other programs

Otherwise, visiting a website wouldn't be much different from downloading a virus. So, modern browsers run a lot of untrusted content inside restricted processes.

Chromium's official description of the Sandbox is very direct: Its goal is to provide clear security guarantees about what code can and cannot do.

You can understand the browser as:

             My Computer

┌───────────────────────────────┐
│                               │
│ Documents                     │
│ SSH Key                       │
│ VS Code                       │
│ Other Programs                │
│                               │
│    ┌─────────────────────┐    │
│    │ Browser Sandbox     │    │
│    │                     │    │
│    │   JavaScript        │    │
│    │   Page Rendering    │    │
│    │                     │    │
│    └─────────────────────┘    │
│                               │
└───────────────────────────────┘

The webpage can still run, JavaScript can still execute, and the page can still display animations and send HTTP requests. It's just that the browser tells it:

Your world ends here.

This is actually the most vivid sentence to describe a Sandbox.

7. Finally, re-understanding Sandbox

Now we can return to the initial question:

Is a Sandbox a virtual environment?

The answer is: Not accurate.

A Sandbox can be implemented with the help of a virtual environment, but it is not itself a virtualization technology. If I were to define a Sandbox now, I would write:

A Sandbox is a controlled code execution boundary. It limits the potential impact of a program to a predetermined scope by restricting the files, processes, network, system calls, and other resources the program can access.

To condense it further:

A Sandbox is not for specifying where a program runs, but for specifying the maximum of what a program can do.

This is also what I believe is the most critical point in understanding a Sandbox. Previously, software was mainly:

Human
↓
Software
↓
Operating System

Humans decided when software runs, but after the emergence of AI Agents, it has slowly become:

Human
↓
AI
↓
AI decides to call tools on its own
↓
Operating System

An additional role capable of autonomous decision-making (AI Agent) has appeared in the middle. Therefore, in the future, we may encounter these concepts more and more frequently:

Sandbox
Permission
Approval
Capability
Isolation

Because when AI only had a "brain," our main concern was:

What did it say wrong?

And when AI starts to have "hands," capable of reading files, writing code, and executing commands, we must also consider another question:

What exactly is it allowed to touch?

A Sandbox is the boundary drawn for these hands.

References

  1. OpenClaw Official Documentation: "Sandbox Isolation" OpenClaw Sandbox Documentation
  2. OpenClaw Official Documentation: "Codex harness" OpenClaw Codex harness Documentation
  3. Docker Official Documentation: "Docker Engine security" Docker Engine security
  4. Chromium Official Documentation: "Sandbox" Chromium Sandbox Design