quicksand README

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

Quicksand

PyPI Changelog Docs License: MIT

Quicksand

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.

🤝 Notable Projects

🚀 Recent Releases

See the changelog for details.

Installation

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

Usage

Boot any container image without Docker or root privileges

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 & running commands

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)

Mount host directories

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)

Configure networking

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:
    ...

Multiple Linux users

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 and load

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__)'")

Checkpoint and revert

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

Control a desktop

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")

Configuration

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",
)

Available images

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.

Building from source

git clone https://github.com/microsoft/quicksand.git
cd quicksand
uv sync
uv run uvr build --all-packages

Documentation

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

Contributing

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

quicksand (microsoft/quicksand)

正在搜索数据库…

这是什么?Quicksand 是一个异步 Python API,用于启动、控制和给 QEMU 虚拟机做快照,专门为隔离运行 AI 智能体(sandbox)而打造。
它是一个独立的应用,还是需要我导入到代码里的库?它是一个安装到你的项目中、通过编程方式调用的 Python 库/API,不是独立的应用程序。
怎么把它跑起来?先安装核心包,再添加 QEMU 和 image 附加依赖以获得内置的运行环境,也可以分开安装;虚拟机镜像(比如 Ubuntu 或 Alpine)通过 `quicksand install ubuntu` 这类命令拉取。
运行沙箱需要 Docker 或 root 权限吗?不需要。运行沙箱既不需要 root 权限也不需要 Docker,因为内置的 QEMU 运行环境会直接处理虚拟化。
沙箱默认能访问互联网吗?不能,沙箱默认是网络隔离的;你必须显式使用 NetworkMode.FULL 才能开放网络,另外还提供定向端口转发,可以实现更可控的访问。
它只能在 Linux 上用吗,还是 macOS 和 Windows 也支持?它同时支持 x86_64 和 ARM64 架构,可用于 macOS、Linux 和 Windows。
智能体能控制沙箱里的完整桌面图形界面吗?可以。ubuntu-desktop 和 alpine-desktop 这类桌面镜像提供完整的 Xfce4 环境,并带浏览器(Firefox 或 Chromium),可以通过 VNC、截图和 QMP 输入注入来控制。
我能保存并恢复沙箱的状态吗?可以。你可以把虚拟机的磁盘状态保存到目录中,之后加载,即使换到另一台机器也行;另外还可以对完整的虚拟机状态做 checkpoint/回滚,出问题时能恢复原状。
quicksand-cua 镜像是做什么用的?它是在 agent 镜像之上的一个叠加层,额外加入了 Xvfb、x11vnc、noVNC、Playwright 和 Chromium,面向需要操作浏览器或桌面的 computer-use 智能体。
多个智能体能安全地共用一个沙箱吗?可以。quicksand 允许你在一个沙箱虚拟机内为多个智能体分配各自独立的 Linux 用户账户。
有哪些类似的项目?nvx, smolvm, CubeSandbox, agentbox, coop, macos, UTM, webvm
作者
microsoft
大小
6.7 MB
星标
425
时长
7个月
提交 · 90 天