项目的 README,来自 github.com/microsoft/quicksand。合并为一个 markdown 文件:README.md。

Quicksand gives AI agents hardware-isolated Linux VMs with zero system dependencies. Install from PyPI on macOS, Windows, or Linux and boot any Docker or OCI container image with no Docker daemon or root privileges required. Control execution, network isolation, host file mounts, and snapshot/restore through a clean async Python API.
Sandbox(image="docker://..."), without Docker even installed.quicksand-kernel, shrinking Alpine to ~8 MB and Ubuntu to ~48 MB (now published directly on PyPI).Forward(Guest(...), Host(...)) lets guests reach services on the host, such as proxies, databases, and APIs.create_user() and execute(user=...) run commands as separate accounts with their own home directories.execute(stdin=...) streams input to commands while output streams back.See the changelog for details.
Install directly from PyPI to boot any OCI or Docker container image in a real VM. Bundled QEMU and the shared guest kernel are included by default (no Docker daemon and no root privileges required):
pip install quick-sandbox
Or include a pre-built offline base image (alpine ~8 MB or ubuntu ~48 MB):
pip install 'quick-sandbox[alpine]'
You can also add extra images with the CLI:
quicksand install alpine # or: quicksand install ubuntu
Prefer your own system QEMU instead of the bundled binary? Install quicksand-core and quicksand-kernel directly:
pip install quicksand-core quicksand-kernel
Boot any container image from Docker Hub, GHCR, or any OCI registry:
import asyncio
from quicksand import Sandbox
async def main():
async with Sandbox(image="python:3.12-slim") as sb:
result = await sb.execute("python3 --version")
print(result.stdout)
asyncio.run(main())
Or open an interactive shell from the terminal:
quicksand run alpine:3.23
Distroless and scratch images without /bin/sh work too by passing an argument list to execute():
async with Sandbox(image="gcr.io/distroless/python3-debian12") as sb:
result = await sb.execute(["/usr/bin/python3", "-c", "print('hi')"])
print(result.stdout)
Or boot a pre-built image package straight from PyPI:
async with Sandbox(image="pypi://quicksand-alpine") as sb:
result = await sb.execute("cat /etc/os-release")
See the Docker & OCI Images guide for custom Dockerfiles, registry auth, and PyPI image packages.
Pre-built images (alpine, ubuntu, and more) work completely offline once installed:
async with Sandbox(image="ubuntu", network_mode=NetworkMode.FULL) as sb:
result = await sb.execute("apt-get update && apt-get install -y python3")
print(result.stdout, result.exit_code)
Share host directories into the VM at boot or on the fly.
# At boot
async with Sandbox(
image="ubuntu",
mounts=[Mount("./workspace", "/mnt/workspace")],
) as sb:
...
# Or dynamically on a running sandbox
handle = await sb.mount("/tmp/data", "/mnt/data")
await sb.execute("ls /mnt/data")
await sb.unmount(handle)
Sandboxes are network-isolated by default. Opt in to internet access with NetworkMode.FULL. Port forwards work in either direction: Forward(Host(...), Guest(...)) exposes a guest port on the host, and Forward(Guest(...), Host(...)) exposes a host service inside the guest, even when the sandbox is otherwise offline.
async with Sandbox(
image="ubuntu",
network_mode=NetworkMode.FULL,
port_forwards=[
Forward(Host(8080), Guest(80)), # host:8080 -> guest:80
Forward(Guest(3128), Host(8080)), # guest 10.0.2.101:3128 -> host:8080
],
) as sb:
...
Give multiple agents independent Linux user accounts in a single sandbox VM.
async with Sandbox(image="ubuntu") as sb:
alice = await sb.create_user("alice")
bob = await sb.create_user("bob")
await alice.execute("cat > hello.txt", stdin="Hello from Alice!\n")
await bob.execute("cat > hello.txt", stdin="Hello from Bob!\n")
for user in (alice, bob):
result = await user.execute("whoami && pwd && cat hello.txt")
print(result.stdout)
await sb.delete_user(user.name)
Save the VM's disk state to a directory. Load it later, even on a different machine.
await sb.execute("pip install numpy pandas")
await sb.save("my-env") # VM keeps running
# Load later
async with Sandbox(image="my-env") as sb:
await sb.execute("python3 -c 'import numpy; print(numpy.__version__)'")
Capture the full VM state and roll back if something goes wrong.
await sb.checkpoint("before-experiment")
await sb.execute("apt install -y something-risky")
await sb.revert("before-experiment") # the VM snaps back to the checkpoint
Desktop images provide a full Xfce4 graphical environment with a browser, published on GHCR (ghcr.io/microsoft/quicksand/ubuntu-desktop and ghcr.io/microsoft/quicksand/alpine-desktop):
async with Sandbox(
image="ghcr.io/microsoft/quicksand/ubuntu-desktop",
enable_display=True,
) as sb:
await sb.screenshot("screen.png")
await sb.type_text("hello world")
await sb.press_key(Key.RET)
await sb.mouse_move(500, 300)
await sb.mouse_click("left")
Here are the main Sandbox configuration options:
Sandbox(
# OCI ref, pypi:// package, local image, or save name
image="python:3.12-slim",
# Guest RAM (default: "512M")
memory="2G",
# Virtual CPU cores (default: 1)
cpus=4,
# Host directories shared into the VM at boot
mounts=[Mount("/host", "/guest")],
# NONE, MOUNTS_ONLY (default), or FULL internet access
network_mode=NetworkMode.FULL,
# Forward TCP ports in either direction (host -> guest, guest -> host)
port_forwards=[Forward(Host(8080), Guest(80)), Forward(Guest(3128), Host(8080))],
# Expand the guest filesystem on boot
disk_size="10G",
# Attach virtual GPU, keyboard, and mouse for screenshot/type_text/mouse control
enable_display=True,
# Auto-save VM state on stop
save="my-save-name",
)
In addition to pulling any container image from an OCI registry (or building from a local Dockerfile), Quicksand ships lightweight offline base wheels on PyPI and larger multi-arch OCI images on GHCR:
| Image | Reference / install | Distribution | What is it |
|---|---|---|---|
alpine |
pip install 'quick-sandbox[alpine]' |
PyPI (~8 MB) | Alpine 3.23 headless (fastest boot) |
ubuntu |
pip install 'quick-sandbox[ubuntu]' |
PyPI (~48 MB) | Ubuntu 24.04 headless |
alpine-desktop |
ghcr.io/microsoft/quicksand/alpine-desktop |
GHCR (OCI) | Alpine 3.23 + Xfce4 + Chromium |
ubuntu-desktop |
ghcr.io/microsoft/quicksand/ubuntu-desktop |
GHCR (OCI) | Ubuntu 24.04 + Xfce4 + Firefox ESR |
agent |
ghcr.io/microsoft/quicksand/agent |
GHCR (OCI) | Ubuntu 24.04 + Python 3.12, uv, build-essential, requests, pyyaml, ddgs, markitdown |
cua |
ghcr.io/microsoft/quicksand/cua |
GHCR (OCI) | Ubuntu 24.04 + Python 3.12, Xvfb, x11vnc, noVNC, Playwright, Chromium |
All images share the ~15 MB quicksand-kernel package at boot. Packages under PyPI's 100 MB limit (quicksand-alpine, quicksand-ubuntu, quicksand-kernel, quicksand-qemu) ship as PyPI wheels; larger (>100 MB) environments are published as multi-arch OCI images on GHCR and require no extra pip install.
git clone https://github.com/microsoft/quicksand.git
cd quicksand
uv sync
uv run uvr build --all-packages
| Topic | Guide | Under the Hood |
|---|---|---|
| Installation | Installing packages | QEMU binaries, kernels, qcow2 disks |
| Docker & OCI Images | Container images, custom Dockerfiles, registry auth | OCI pull, ext4 builder VM, image caching |
| Sandbox Lifecycle | Creating and configuring sandboxes | -m, -smp, -accel, machine types |
| Running Commands | execute(), streaming, exit codes |
Kernel boot, agent tokens, hostfwd |
| File Exchange | Mounts, hot-mounts, getting data in/out | CIFS via guestfwd, 9p via -fsdev |
| Save and Rollback | Checkpoints, reverts, persistent saves | qcow2 overlays, savevm, blockdev-snapshot-sync |
| Desktop Control | Screenshots, keyboard, mouse | VNC, GPU, USB tablet, QMP input injection |
| Network and Isolation | Network modes, port forwarding | SLIRP NAT, restrict=on, guestfwd |
| Performance | What makes it fast | io_uring, IOThreads, TCG vs KVM |
| Guide | When to use |
|---|---|
| Creating Images | Build a new image package |
| Extending the Sandbox | Add a method, OS, architecture, or QEMU flag |
| Testing | Run or write tests |
| Releasing | Cut a release |
Full guides: User Guide | Under the Hood | Contributor Guide