
An isolated AI sandbox runs a task with explicitly bounded credentials, filesystem access, network permissions and compute. Record what it may read, where it may write, and who can stop it.
When an AI agent only chats, the worst it can do is say something wrong. When it can run shell commands, install packages, edit files and call APIs, it can also do something wrong. A sandbox puts those actions in a box.
OpenAI's Agents SDK documentation describes a sandbox as an isolated, Unix-like environment with a filesystem, a shell, installed packages, mounted data, exposed ports and snapshots. It also separates the sandbox from the "harness," the control layer that keeps authentication, billing, audit logs and human review outside the box. That split is the core design idea: the agent can be creative inside the sandbox, but the things that matter live where it cannot reach them.
Arize's glossary gives a useful checklist of what a sandbox controls: the filesystem, the network, processes and resources, and credentials. If your setup limits all four, it is a sandbox. If it limits one or two, it is a partial fence.

You may also see the same idea called a sandbox environment for AI agents. The name changes between vendors, but the questions are the same: where does the agent's code run, what can it see, and what can it send out?
There are three ingredients that turn an agent from helpful into risky. The researcher Simon Willison calls them the lethal trifecta: access to private data, exposure to untrusted content, and a way to communicate externally. An agent that reads a web page, holds your API keys and can make outbound requests has all three. A hidden instruction in that page (a prompt injection) can tell it to send the keys somewhere.
The practical rule that follows: do not let one agent session combine all three without a human check. A sandbox helps by removing at least one of them by default, usually the private data and the open network.
The threats a sandbox is meant to contain are concrete:
In each case, the question is the same: what is within reach of the agent's process? A sandbox shrinks the answer.
For a wider look at how data leaks from language-model workflows and how IT teams rank those risks, this guide to mapping LLM leakage attack surfaces is a good companion to the setup steps below.
The main choice is how hard the wall between the agent and everything else should be.
| Option | What it is | Kernel | Best for |
|---|---|---|---|
| Container | Isolated processes on a shared operating system | Shared with the host | Your own code and known tools |
| MicroVM | A very small virtual machine with a minimal setup | Its own | Untrusted or agent-written code |
| Full virtual machine | A complete virtual server | Its own | Long-running agents, desktops, persistent work |
The kernel is the core of the operating system. Containers share the host's kernel, so a flaw in the kernel or the container runtime can become access to the host. A well-known example is CVE-2019-5736, a flaw in the runc container runtime, which let a malicious process overwrite the host's runc binary, as described in this write-up. It was patched long ago, but it shows why running untrusted code in a plain container on your own machine is a bet.
A virtual machine or microVM has its own kernel, so a bug in agent-generated code or a vulnerable dependency has one more wall to cross before it reaches the host. That is why untrusted code belongs in a VM-style boundary, and why we recommend a separate virtual server for an agent that installs software and runs commands on its own.
One caution applies to every option: the likelier failure for a team running its own sandbox is a configuration mistake, not an exotic escape. A permissive network rule or a mounted host directory defeats a strong wall.
Give the agent a copy of the project, not your home directory. The lifecycle SpecStory describes starts from a base image plus a project copy, lets commands change only sandbox files, then copies the results out and deletes or resets the sandbox. That last step is what makes mistakes cheap.
OpenAI's write-up of the Codex sandbox shows the same idea at the operating-system level: by default the agent can write in its workspace, key folders such as .git stay read-only, and network access is off. Read-only protection for the things you cannot afford to lose is a good habit on any setup.
Network control is where most leaks are stopped. The strongest default is no outbound access, then an allowlist of hosts the task needs: a package registry, your Git host, the model API. The Codex post also notes that even a DNS lookup can leak information, so the hostname should be checked before it is resolved.
If your agent only needs to talk to a model API, allow that and nothing else. If it needs to install packages, allow the registry during setup and shut it afterward.
The same logic applies to the credentials that the agent uses to call model APIs. This guide on conditional access design rules is a helpful read on keeping access limited to the right conditions.
Set CPU, memory and disk limits so a runaway loop cannot starve everything else, and set a time limit so forgotten sandboxes get cleaned up. With a virtual server, the size you choose is the limit. We size servers per unit, so a small agent does not need to pay for a large machine.
The safest pattern is that real secrets never enter the sandbox. Give the agent narrow, test-scoped keys. Where it must call an authenticated service, put the real key outside and add it to the request at a proxy, so the agent only ever holds a placeholder. Rotate any key the agent has seen.
Two cautions for step 3. If you mount a host folder read-write, the agent can change those files, so mount only the project. And any tool server that runs on your host rather than inside the sandbox sits outside the wall, so treat it as part of your own machine.
An agent that connects to tools through MCP (the Model Context Protocol, a standard way to give agents tools) adds another door. List which tools the agent can call and what each can touch. For threat modeling and approval steps in agent sessions, the LLM leakage guide above pairs well with this checklist.
| Requirement | Test |
|---|---|
| Compute boundary | Verify resource limits with a representative job. |
| Data boundary | Use sanitized input and prove the job cannot read unrelated data. |
| Credentials | Use a revocable identity scoped to this task. |
| Cost | Separate host charges, workspace management and model API usage. |
Use a compatible machine in a customer account or site, or obtain an offer for a qualified external provider. Virtual datacenter
An ephemeral sandbox lives for one task and is deleted with its disk. It is the strongest default because nothing carries over, so a poisoned session cannot affect the next one. A persistent sandbox keeps files and installed tools between sessions, which suits a coding assistant or a long-running agent.
If you go persistent, take snapshots or keep a rebuild script so you can return to a known-good state. Check also whether state can leak between users if anything is shared; with a dedicated server per agent, that question does not arise.
For personal or otherwise sensitive data, document the compute region, model API, storage and access boundaries. Prefer synthetic or redacted input for experiments and confirm retention before allowing real records into the sandbox.
When the job finishes, revoke its credentials and destroy its writable state according to the retention policy. Start a new run from the recorded image and confirm it cannot see the previous job’s files. Keep the minimum audit evidence required for the experiment.
On a Linux host using cgroup v2, inspect the current boundary from inside the disposable worker. A value of max means that this cgroup does not impose that particular ceiling. Compare the result with the intended job budget.
cat /sys/fs/cgroup/memory.max /sys/fs/cgroup/pids.max
If the agent will call tools over MCP or you want it to manage servers itself, our AI hosting page and AI infrastructure guide show what to run and how to connect it.
It is enough for code you wrote and tools you trust. Containers share the host's kernel, so for code an agent writes or downloads, a virtual machine or microVM with its own kernel is the safer boundary. Either way, the network and credential settings decide how much damage a mistake can do.
It cannot stop an agent from reading a malicious instruction, but it limits what that instruction can achieve. If the sandbox has no real secrets and no open outbound network, there is little to steal and nowhere to send it. Keep a human approval step for anything that touches real systems.
Start with none, then allow only the hosts the task needs, such as a package registry or a model API. Open access is the most common way a sandbox stops being one. Allow the registry during setup and close it afterward when you can.
The cost depends on the machine, task duration, storage and separately billed inference. Use the operator’s current quote for the compute and SAU pricing for workspace management.
Yes. Connect a supported cloud account or enroll a compatible site host, then check isolation on that specific machine before running an experiment.
Explore With AI & Cite This Page
Open a grounded prompt in your AI assistant or copy a clean Markdown, HTML, or APA reference link.
Validate protocols and subnets directly in your browser or continue reading related architecture notes.
UFW Firewall Rule Generator & Chmod Calculator
Free Docker Compose Security Linter & Audit
Free WHOIS & RDAP Domain & ASN Lookup Tool
Isolated Development Environment: What It Is and How to Build One
An isolated development environment keeps each project's code, dependencies and data apart. See how to build one with containers, VMs or a cloud server.
Sandbox Development Environments: What They Are and How to Run One
What a sandbox development environment is, how it differs from a dev environment, and how to set up an isolated, browser-accessible sandbox server for code, AI and games.
Custom Server Configuration: How to Size, Build and Secure Yours
Learn how to configure a custom server: size CPU, RAM and storage from real data, lock down access, test, and resize later, all from one browser console.
AI Development Server: What You Need and How to Set One Up
Choose CPU, memory, storage and network for an AI development server. Compare external compute, model API usage and workspace costs, then verify the browser access path.