- 1
Client.spawn()The agent installs the package and starts a virtx server on your machine.
- 2
build_image(recipe, "jq:latest")It builds an image with the tools the commands need, and reads the build log to its end.
- 3
create_sandbox("jq:latest", volumes=[SandboxVolume(data, "/data")])It boots a sandbox from the image, with the volume that holds the input.
- 4
exec(["sh", "-c", "jq . /data/in.json > /data/out.json"])It runs the command. What lands on /data is on the volume.
- 5
sandbox.remove()It reads out.json from the volume, not just the exit code, then removes the sandbox.
A microVM sandbox for coding agents
Install the virtx skill in your coding agent, and the commands a task should not run on your host go to a disposable Linux microVM.
- Claude Code
- Codex
- your own agent
| The task needs | The agent passes |
|---|---|
| a tool the image lacks | build_image(recipe, "jq:latest") |
| files kept for the next sandbox | volumes=[SandboxVolume("data", "/data")] |
| files it must not change | SandboxVolume("data", "/data", readonly=True) |
| no network | network=False |
| a server in it, reached from here | ports=[8000] |
| the host’s GPU | gpu=True |
- One sandbox per task
- Own Linux kernel per sandbox
- Python, Node.js and Rust
- Linux, macOS and Windows 11
- No Docker
- Open source
A task, as the agent runs it
The agent edits your code where it is. The commands that test it go to a sandbox.
- you
Add a --json flag to report.py and run the tests.
Edit(report.py)hostvolume.write_file("report.py", code)volumecreate_sandbox("py-test:latest", volumes=[SandboxVolume(work, "/work")])sandboxexec(["sh", "-c", "cd /work && pytest -q"])sandbox└ 3 passed in 0.08ssandbox.remove()sandbox- agent
The tests pass. They ran in a sandbox, not on your host.
- host
The agent, its shell, your repository and the edits it makes to it.
- volume
What the commands read, and what they leave behind. It outlives the sandbox.
- sandbox
The commands the task should not run on your host, and all they install. Gone on remove().
Install the virtx skill in Claude Code or Codex
The virtx repository is a plugin marketplace, so either agent installs the skill with one line.
claude plugin marketplace add brekkylab/virtx && claude plugin install virtx@brekkylabcodex plugin marketplace add brekkylab/virtx && codex plugin add virtx@brekkylab- The virtx packageThe agent installs it for your project:
pip install virtx,npm install @brekkylab/virtxorcargo add virtx. - A virtx server
Client.spawn()starts one on your machine.Client.connect(url, auth)reaches one over HTTP. - No checkout of virtxThe skill works without a clone of the repository.
The five steps the skill follows in each task
Follow one task through the sandbox’s console.
$ pip install virtx> Client.spawn()> build_image(recipe, "jq:latest")STEP 1/1: RUN apk add --no-cache jq(1/2) Installing oniguruma (6.9.10-r0)(2/2) Installing jq (1.8.2-r0)OK: 9103 KiB in 18 packages> create_sandbox("jq:latest", volumes=[SandboxVolume(data, "/data")])sandbox ff3168aa$ jq . /data/in.json > /data/out.jsonexited 0> data.read_text("out.json"){"task": "reshape","rows": 2}> sandbox.remove()
Give your own agent a sandbox as a tool
A sandbox is a tool like any other, so any agent framework can drive one. This function runs a shell command in a sandbox and answers what it printed, for your agent to call.
import asyncio
from virtx import Client, SandboxJobEnd, Stderr, Stdout
async def run_in_sandbox(sandbox, command: str) -> str:
"""Your agent's tool: run a shell command in the sandbox, answer what it printed."""
out = []
async for entry in sandbox.exec(["sh", "-c", command], timeout_ms=60_000):
match entry.entry:
case Stdout(line) | Stderr(line):
out.append(line)
case SandboxJobEnd(code):
out.append(f"exited {code}")
return "\n".join(out)
async def main() -> None:
async with Client.spawn() as client:
await client.pull_image("python:3.12-slim-trixie").complete()
sandbox = await client.create_sandbox("python:3.12-slim-trixie", network=False)
try:
# hand run_in_sandbox to your agent; here it runs one command
print(await run_in_sandbox(sandbox, "python -c 'print(6 * 7)'"))
finally:
await sandbox.remove()
asyncio.run(main())The Node.js and Rust clients make the same calls. Running commands
One sandbox per task, side by side
A virtx server runs several sandboxes at once. Each task gets its own, from the image it needs and with only what it asks for, and it is gone when the task is done.
- Run the test suiteexited 0
$ pytest -q - Build the frontendexited 0
$ npm run build - Reshape the dataexited 0
$ jq -f shape.jq in.json - Bench the parserexited 0
$ cargo bench
Questions about coding agents in VirtX
Something else? Ask on Discord.
Does Claude Code itself run inside the microVM?
No. Claude Code or Codex runs where you started it, with its own shell and git. Through the skill, the commands a task should not run on your host, and the files they write, go to a sandbox.
Which languages can the agent use?
Python 3.11 or later, Node.js 22 or later, and Rust 1.89 or later. The skill installs the package for the language your project uses.
What happens to what the agent installs in a sandbox?
It is deleted with the sandbox. To keep tools for the next sandbox, build them into an image with build_image; to keep files, write them to a volume.
Keep reading
The guide and docs tutorials behind each step.
- Using virtx in coding agentsInstall the skill, and the steps it follows.
- Hello worldYour first sandbox in one program.
- Working with imagesBuild one from a recipe, or pull one.
- Running commandsStream a job’s output, set a timeout.
- Mounting volumesKeep files across sandboxes.
- Untrusted codeHow far an escape from a microVM gets, next to a container.
Give your agent a sandbox
Free and open source on your own machine. VirtX cloud is in early access.
pip install virtxnpm install @brekkylab/virtxcargo add virtx