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.

Runs code from
  • Claude Code
  • Codex
  • PyPI
  • npm
  • your users
untrusted codeVirtX microVM · network=False
It tries toIn the sandbox
read ~/.ssh/id_ed25519not thereOnly the files you hand in are inside.
reach example.comblockednetwork=False: Failed to resolve 'example.com'.
reach 127.0.0.1:5432blockedYour loopback and private network stay out of reach.
break out of the kernelcontainedIt is the VM’s own kernel. The hypervisor is in the way.
write /root/.cache/deletedGone when the sandbox is removed.
write /data/report.csvkeptKept on the volume you mounted.

How far an escape gets

The same breakout, from a container and from a VirtX microVM.

  1. untrusted code
  2. namespaces
  3. your kernel, shared
  4. ~/.ssh.env~/src
ContainerThrough the shared kernel, it lands on your machine.
  1. untrusted code
  2. its own Linux kernel
  3. hypervisor
  4. your kernel
  5. ~/.ssh.env~/src
VirtX microVMThrough the VM’s own kernel, it reaches the hypervisor and stops there.
Read MicroVM vs Container

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.

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())
terminal
$ python run.py
Traceback (most recent call last):
...
requests.exceptions.ConnectionError: ...
Failed to resolve 'example.com'
sum: 45
exited 1

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

  1. 1sandbox.write_file("main.py", code)

    Only what you hand in goes in. Nothing else from your machine is there.

  2. 2sandbox.exec(["python", "/main.py"])

    It writes where it likes: its own disk, and the volume mounted at /data.

  3. 3sandbox.remove()

    The sandbox and everything on its disk are deleted. The volume stays.

  4. 4volume.read_text("report.csv")

    Read the results from the volume, with no sandbox running.

your machine
  • ~/.ssh
  • .env
  • main.pyhanded in
  • report.csvfrom the volume
sandbox diskrunning
  • /main.py
  • /tmp/scratch/
  • /root/.cache/
volume: resultsmounted at /data
  • 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 laptopA Docker containerVirtX microVM
KernelYoursYours, sharedIts own Linux kernel
Your filesAll of themWhatever you mountOnly what you hand in or mount
NetworkOpenOpen unless you turn it offOff with network=False
An escape lands onNothing to escapeYour kernelThe hypervisor
When it is doneWhat it wrote staysKept until you remove itDeleted on remove(); volumes kept
To set upNothingDocker, installed and runningpip 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.

Run the next script in a VM

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

pip install virtx