The layer between agent runtimes and microVMs.
One sandbox API for running untrusted agent code: Firecracker in production, Docker on your laptop and in CI (a libkrun backend for macOS microVMs is planned). Snapshot, restore and fork as first-class operations. Not a hosted product: a daemon plus SDKs you embed in your own platform.
from vmlayer import Sandbox, Volume
with Sandbox.create("python:3.12", memory_mb=512) as sb:
sb.files.write("/work/main.py", "print('hello from a sandbox')")
print(sb.exec("python /work/main.py").stdout)
snap = sb.snapshot() # whole sandbox, restorable later
sb2 = Sandbox.restore(snap) # own clone of every volume
# a workspace that outlives any one sandbox
repo = Volume.create(name="proj-42", size_mb=8192)
with Sandbox.create("python:3.12", workspace=repo) as sb:
sb.exec("git clone https://example.com/repo .")
ckpt = repo.snapshot() # files only, milliseconds
with Sandbox.create("node:22", workspace=repo) as sb:
sb.exec("npm test") # same files, different image| Piece | State |
|---|---|
vmlayerd daemon, gRPC API, Python SDK, TypeScript SDK, vmlayer CLI |
working, tested end to end |
| Docker backend (Linux, macOS, CI) | working: exec, pty, files, volumes, filesystem snapshots, restore, expose, TTLs |
| Volumes: named/anonymous, single-writer rule, copy-on-write snapshots and clones | working (directory and ext4 block-image kinds) |
| Guest agent (PID 1 in the VM; exec, files, pty, mounts over vsock) | working, tested end to end in a container |
| Image pipeline for microVMs (OCI pull → cached ext4, no Docker needed) | working, tested on Linux with a real pull |
| Firecracker backend (memory snapshots, fork) | working; end-to-end tests in CI on x86_64 KVM and locally on aarch64 nested KVM (setup, benchmark) |
| libkrun backend (macOS microVMs) | planned |
| Network isolation (no access to the host, other sandboxes or cloud metadata), egress allowlists by network or DNS name, network and disk rate limits | working on Firecracker, tested end to end in CI (usage, design) |
Durable memory snapshots: resume a running Firecracker sandbox on another host of the same type (snapshot(durable=True)) |
working, tested end to end on KVM (design) |
| Durable volume snapshots in S3, Azure Blob, GCS or a shared directory (incremental, deduplicated, move between hosts) | working; tested against MinIO and Azurite in CI (usage, design) |
Framework adapters: mini-swe-agent Environment, AutoGen CodeExecutor |
working, tested against the real frameworks (docs) |
Deep Agents BaseSandbox, OpenHands RemoteWorkspace |
working in local Firecracker experiments (docs) |
E2B compatibility: unmodified E2B SDK code runs against vmlayer by changing two addresses (vmlayer-e2b-server), plus a source-level facade (vmlayer.e2b) |
working, tested with the real E2B Python SDK (mapping, design) |
Several hosts without a scheduler service: host registry, host leases and ownership epochs in the blob store, placement and admission control in the daemons (vmlayer.Cluster in Python and TypeScript), single-instance sandboxes (lease=) fenced by a per-VM shim |
working, tested end to end with two daemons (usage, design) |
Automatic rescheduling from dead hosts: periodic workspace checkpoints, any daemon with --rescue recreates the sandbox (reschedule=True) |
working, tested end to end by killing a host (design) |
| Lazy restore: Firecracker volumes from the blob store are usable at once, fetched on demand through NBD | working, tested end to end on KVM (design) |
asyncio client (vmlayer.aio, native grpc.aio) |
working, tested against the daemon |
| Callers: TLS and mutual TLS, tokens with a tenant and a role (read, write, admin) | working, tested with a mutual-TLS daemon serving two tenants (deploy, design) |
Harbor environment (vmlayer.integrations.harbor): Terminal-Bench and other Harbor datasets on vmlayer sandboxes |
working, tested with Harbor's CLI on Docker and Firecracker (integrations) |
Run commands as another user (exec(user=...)) |
working on Docker and Firecracker |
API keys that never enter the sandbox: a credential proxy swaps placeholders for real secrets on the way out (credentials=[...]) |
working on Docker and Firecracker (usage, design) |
Exposed ports on an authenticated HTTPS gateway (expose(port, gateway=True)): https://<port>-<sandbox>.<domain>, a token per port, WebSockets |
working, tested end to end (deploy, design) |
Deployment: release binaries, a container image (Dockerfile), a Kubernetes DaemonSet, Prometheus metrics, per-request IDs in logs |
image and manifest built and validated in CI (deploy, kubernetes) |
| More adapters (ADK, SWE-ReX, smolagents), E2B PTY and watchers | planned |
The API is designed for all backends; what a backend cannot do it refuses
with BackendUnsupported, never approximates. Sandbox.capabilities says
which is which.
Requirements: Docker (Docker Desktop, colima, OrbStack or a Linux engine),
Rust 1.80+, protoc, Python 3.10+ with uv.
git clone https://github.com/chrisyifanjin/vmlayer && cd vmlayer
cargo build --release # vmlayerd and vmlayer in target/release
./target/release/vmlayerd & # listens on ~/.vmlayer/vmlayerd.sock
./target/release/vmlayer info
./target/release/vmlayer run python:3.12-alpine 'python3 -c "print(6*7)"'Python SDK (from the checkout until the first PyPI release):
cd sdk/python && uv sync && uv run python -c "
import vmlayer
with vmlayer.Sandbox.create('alpine:3.20') as sb:
print(sb.exec('uname -a').output)
"TypeScript (same API, await using cleans up):
import { Sandbox } from "vmlayer";
await using sb = await Sandbox.create("python:3.12-alpine");
console.log((await sb.exec("python -c 'print(6*7)'")).stdout);See docs/usage.md for the SDK guide, examples/ for runnable programs, and docs/deploy.md for running the daemon as a service.
Every team building an agent runtime ends up writing the same thing: a way to boot an isolated environment, run commands in it, move files in and out, and throw it away. Most reach for Docker, then discover they want real isolation, memory snapshots and forking, and start over on Firecracker.
The pieces exist but there is nothing in the middle:
| Layer | What's there | Problem |
|---|---|---|
| VMMs | Firecracker, libkrun, cloud-hypervisor | Too low-level. You still write networking, images, agent, lifecycle. |
| Hosted sandboxes | E2B, Modal, Daytona, Vercel Sandbox... | You rent them. Self-hosting is their full stack or nothing. |
| Local microVM libs | microsandbox, smolvm | One VMM each, no daemon mode, no Firecracker. |
vmlayer is the missing middle: a pluggable-backend sandbox runtime that an agent platform can depend on the way it depends on a database driver. It was checked against the sandbox interfaces of six open-source agent runtimes (docs/integrations.md) and the systems research on microVM snapshots (docs/research.md).
The agent loop, credentials, and model calls can stay in the host control
plane. A framework adapter sends only sandbox tool calls to vmlayerd, which
creates a Firecracker microVM directly on a KVM host. Kubernetes may schedule
and restart those hosts, but a sandbox create does not create a Kubernetes pod
or put the control plane in a VM. OpenHands is an optional second pattern:
its agent server runs inside the sandbox when that framework needs it.
Head-to-head numbers against the sandboxes that mini-swe-agent and AutoGen ship are in the benchmarks.
The local Agent Sandbox + gVisor comparison measures the pod-per-sandbox alternative. Kubernetes can use VM-backed RuntimeClasses such as Kata; the distinction here is the sandbox request path and lifecycle, not a claim that Kubernetes cannot run VMs.
For tools that need no mounted workspace volume, the Firecracker backend can
restore each new VM from an on-disk, data-free boot template. This is optional
(firecracker.template_snapshots = true) and keeps no idle VM alive. See the
cold-path benchmarks and limits.
Python SDK / CLI / (TypeScript) your agent runtime links one of these
│ gRPC (unix socket, or TCP + token)
▼
┌──────────────────────────────────┐
│ vmlayerd │ one binary per host
│ · sandbox table (SQLite) │
│ · volumes: clone, snapshot │ copy-on-write where the FS allows
│ · process buffers, TTLs │
│ · picks a Backend │
└──────────────┬───────────────────┘
│ Backend trait (core/)
┌───────────┼─────────────┐
▼ ▼ ▼
firecracker libkrun docker
Linux + KVM (planned) anywhere
production macOS laptop, CI
│
▼
guest agent (vsock): exec, files, pty, mounts
Rules the design holds itself to:
- The unit is a sandbox, never a VM. Callers do not see vCPUs, tap devices or rootfs paths.
- Same API on every backend. What a backend cannot do is declared in
Capabilitiesand refused with an error. Never approximated. - Snapshot / restore / fork are the point. They are the reason to pick a microVM over a container, so they shape the API instead of being bolted on.
- Thin SDKs, one daemon. Policy lives in
vmlayerd. SDKs are generated clients plus ergonomics. - Images resolved in one place. Backends receive a
Rootfs, never an OCI reference. - Root disk and workspace are separate. The root disk is disposable; work
lives on a
Volumethat can outlive the sandbox, be shared read-only, be checkpointed cheaply, and is cloned (never reattached) on restore and fork. Anonymous by default, so most callers never see it. - Cloud-agnostic. Linux + KVM is the only hard dependency for microVMs; no cloud APIs, no managed services. See decision 0005.
The contract lives in two places: sdk/python/vmlayer/
(what callers see) and core/src/backend.rs (what a
backend implements). Every non-obvious choice has a record in
docs/decisions/.
| Firecracker | libkrun | Docker | |
|---|---|---|---|
| Runs on | Linux + KVM | macOS (Apple Silicon), Linux | Anywhere dockerd runs |
| Isolation | microVM, own kernel | microVM, own kernel | container |
| Memory snapshot | yes | planned | no (filesystem only) |
| Fork | yes | planned | no |
| Status | working; CI on x86_64 KVM, development on aarch64 nested KVM | planned | working |
Backend.AUTO picks the strongest one the host supports.
vmlayer depends on Linux and, for microVM backends, /dev/kvm. Nothing
cloud-specific: no metadata service, no VPC API, no managed database. State
is SQLite; snapshots are on local disk, and durable volume snapshots go to
any S3-compatible store, Azure Blob, GCS or a shared directory.
| Host | Firecracker backend | Notes |
|---|---|---|
| Bare metal (any provider, on-prem) | yes | best performance |
AWS C8i / M8i / R8i, .metal |
yes | nested virt on standard instances since Feb 2026 |
| GCP, nested virt enabled | yes | per-instance flag |
| Azure v3+ families | yes | Hyper-V nesting |
| OCI, select VM shapes or BM | yes | |
| Hetzner Cloud | yes | cheapest dev box |
| Alibaba ECS Bare Metal | yes | standard ECS: no KVM, Docker fallback |
| Any Linux without KVM | Docker fallback | same API, container isolation |
| macOS (Apple Silicon) | libkrun backend (planned) | Docker meanwhile |
proto/ vmlayer.v1 gRPC contract (the wire API)
core/ Backend trait, shared types, errors; no implementation
daemon/ vmlayerd
backends/docker/ Docker backend
backends/firecracker/ Firecracker backend (jailer, netns, vsock)
guest-agent/ static PID 1 agent for microVMs
procs/ process table shared by daemon and agent
cli/ vmlayer command
sdk/python/ Python SDK and end-to-end tests
sdk/typescript/ TypeScript SDK and end-to-end tests
examples/ runnable examples
deploy/ container config and Kubernetes DaemonSet (Dockerfile at the root)
docs/decisions/ design records docs/research.md papers that shaped it
docs/integrations.md six agent runtimes mapped onto the API
Billing, multi-tenant user management, a web UI, service mesh. Those make a product. vmlayer is a library.
See CONTRIBUTING.md, the code of conduct and the security policy. Changes are listed in CHANGELOG.md.
Apache-2.0.