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.

Works in
  • Claude Code
  • Codex
  • your own agent
virtx skillone sandbox per task
The task needsThe agent passes
a tool the image lacksbuild_image(recipe, "jq:latest")
files kept for the next sandboxvolumes=[SandboxVolume("data", "/data")]
files it must not changeSandboxVolume("data", "/data", readonly=True)
no networknetwork=False
a server in it, reached from hereports=[8000]
the host’s GPUgpu=True

A task, as the agent runs it

The agent edits your code where it is. The commands that test it go to a sandbox.

agent sessionvirtx skill
  1. you

    Add a --json flag to report.py and run the tests.

  2. Edit(report.py)host
  3. volume.write_file("report.py", code)volume
  4. create_sandbox("py-test:latest", volumes=[SandboxVolume(work, "/work")])sandbox
  5. exec(["sh", "-c", "cd /work && pytest -q"])sandbox└ 3 passed in 0.08s
  6. sandbox.remove()sandbox
  7. 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@brekkylab
  • The virtx packageThe agent installs it for your project: pip install virtx, npm install @brekkylab/virtx or cargo add virtx.
  • A virtx serverClient.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.

  1. 1Client.spawn()

    The agent installs the package and starts a virtx server on your machine.

  2. 2build_image(recipe, "jq:latest")

    It builds an image with the tools the commands need, and reads the build log to its end.

  3. 3create_sandbox("jq:latest", volumes=[SandboxVolume(data, "/data")])

    It boots a sandbox from the image, with the volume that holds the input.

  4. 4exec(["sh", "-c", "jq . /data/in.json > /data/out.json"])

    It runs the command. What lands on /data is on the volume.

  5. 5sandbox.remove()

    It reads out.json from the volume, not just the exit code, then removes the sandbox.

sandboxjq:latest · /datano sandbox
$ 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.json
exited 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.

agent_tool.py
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())
terminal
$ python agent_tool.py
42
exited 0

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.

How a microVM compares with a container

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.

Give your agent a sandbox

Free and open source on your own machine. VirtX cloud is in early access.

pip install virtx