- 1
sandbox.write_file("main.py", code)Only what you hand in goes in. Nothing else from your machine is there.
- 2
sandbox.exec(["python", "/main.py"])It writes where it likes: its own disk, and the volume mounted at /data.
- 3
sandbox.remove()The sandbox and everything on its disk are deleted. The volume stays.
- 4
volume.read_text("report.csv")Read the results from the volume, with no sandbox running.
Run untrusted code safely
A sandbox for code an AI agent just wrote, packages you have not read and scripts your users send in. Each runs in a disposable microVM with its own Linux kernel, away from your files and keys.
- Claude Code
- Codex
- PyPI
- npm
- your users
| It tries to | In the sandbox |
|---|---|
read ~/.ssh/id_ed25519 | not thereOnly the files you hand in are inside. |
reach example.com | blockednetwork=False: Failed to resolve 'example.com'. |
reach 127.0.0.1:5432 | blockedYour loopback and private network stay out of reach. |
break out of the kernel | containedIt is the VM’s own kernel. The hypervisor is in the way. |
write /root/.cache/ | deletedGone when the sandbox is removed. |
write /data/report.csv | keptKept on the volume you mounted. |
- Own Linux kernel per sandbox
- Network off per sandbox
- Gone when removed
- Runs on your laptop
- Python, Node.js and Rust
- Open source
How far an escape gets
The same breakout, from a container and from a VirtX microVM.
- untrusted code
- namespaces
- your kernel, shared
- ~/.ssh.env~/src
- untrusted code
- its own Linux kernel
- hypervisor
- your kernel
- ~/.ssh.env~/src
Where untrusted code comes from
Anything you would not run on your laptop without reading it first, and the one call that runs it in a sandbox.
Code an agent just wrote
Run it the moment it exists, before anyone has read it. One sandbox per task.
sandbox.exec(["python", "/main.py"])Code your users send in
A code interpreter, a grader, a playground: one sandbox per request, with the network off.
client.create_sandbox("agent-python:latest", network=False)A PyPI package you have not read
Its install runs in the VM, so whatever its setup does stays there.
Recipe("python:3.12-slim").run("pip install requests")An npm package and its install scripts
Postinstall scripts run inside the sandbox, not on your laptop.
Recipe("node:22").run("npm install left-pad")
Turn the network off with one argument
The same script with each setting, and what it printed on virtx 0.2.1. With the network off, the sandbox makes no outbound connections or name lookups.
import asyncio
from virtx import Client, Recipe
# Code a model wrote, run without reading it first.
generated = """
import requests
print("sum:", sum(range(10)))
print("status:", requests.get("https://example.com", timeout=5).status_code)
"""
async def main() -> None:
async with Client.spawn() as client:
recipe = Recipe("python:3.12-slim").run("pip install requests")
await client.build_image(recipe, "agent-python:latest").complete()
sandbox = await client.create_sandbox("agent-python:latest", network=False)
try:
await sandbox.write_file("main.py", generated)
job = sandbox.exec(["python", "/main.py"], timeout_ms=30_000)
print("exited", await job.complete(print=True))
finally:
await sandbox.remove()
asyncio.run(main())import asyncio
from virtx import Client, Recipe
# Code a model wrote, run without reading it first.
generated = """
import requests
print("sum:", sum(range(10)))
print("status:", requests.get("https://example.com", timeout=5).status_code)
"""
async def main() -> None:
async with Client.spawn() as client:
recipe = Recipe("python:3.12-slim").run("pip install requests")
await client.build_image(recipe, "agent-python:latest").complete()
sandbox = await client.create_sandbox("agent-python:latest", network=True)
try:
await sandbox.write_file("main.py", generated)
job = sandbox.exec(["python", "/main.py"], timeout_ms=30_000)
print("exited", await job.complete(print=True))
finally:
await sandbox.remove()
asyncio.run(main())With the network on, a sandbox still cannot reach your machine’s loopback or private addresses. Networks and ports
What happens to the files it writes
Follow one run. Only the volume outlives it. Mounting volumes
- ~/.ssh
- .env
- main.pyhanded in
- report.csvfrom the volume
- /main.py
- /tmp/scratch/
- /root/.cache/
- report.csvkept
Your laptop, a Docker container or a microVM
Where the same LLM-generated code can run, and what it can touch from there.
| Your laptop | A Docker container | VirtX microVM | |
|---|---|---|---|
| Kernel | Yours | Yours, shared | Its own Linux kernel |
| Your files | All of them | Whatever you mount | Only what you hand in or mount |
| Network | Open | Open unless you turn it off | Off with network=False |
| An escape lands on | Nothing to escape | Your kernel | The hypervisor |
| When it is done | What it wrote stays | Kept until you remove it | Deleted on remove(); volumes kept |
| To set up | Nothing | Docker, installed and running | pip install virtx, no Docker |
Questions about running untrusted code
Something else? Ask on Discord.
Is a Docker container enough for LLM-generated code?
A container shares your kernel, so a kernel exploit from inside lands on your machine. A VirtX sandbox runs its own Linux kernel in a microVM, and an escape from it reaches the hypervisor.
Can the code reach my localhost or private network?
Not with network=False: the sandbox makes no outbound connections or name lookups. With the network on, it still cannot reach your machine’s loopback or private addresses.
How do I control which files and network an AI agent can reach?
Per sandbox. It sees only what you write into it with write_file and the volumes you mount, read-write or read-only; your home directory, keys and .env files are not there. Pass network=False to block its outbound connections and name lookups.
What is left when it finishes?
remove() deletes the sandbox and everything on its disk. A volume stays, so the results you mean to keep go there.
Can I run LLM-generated code on macOS or Windows without Docker Desktop?
Yes. VirtX runs on your laptop, on Linux, macOS and Windows 11, from Python, Node.js or Rust, with no Docker or daemon to set up. VirtX cloud is in early access.
Keep reading
The docs tutorials behind each call, and the longer story on microVMs.
- Coding agentsClaude Code, Codex and your own agents, running their commands in a sandbox.
- Networks and portsTurn the network off, open only the ports you need.
- Mounting volumesKeep results across sandboxes.
- Running commandsFollow a job’s log, stop it with a timeout.
- MicroVM vs ContainerWhere each isolation boundary sits.
- What Is a MicroVM?How a microVM differs from a VM and a container.
Run the next script in a VM
Free and open source on your own machine. VirtX cloud is in early access.
pip install virtxnpm install @brekkylab/virtxcargo add virtx