What is SmolVM?
SmolVM is built on top of Firecracker microVMs and provides a high-level Python SDK for managing VM lifecycles, networking, and command execution. It’s specifically designed to provide a secure “sandbox” for AI agents to execute code, browse the web, or perform system-level tasks safely.Why MicroVMs?
AI agents often need to execute arbitrary code (Python, JS, shell scripts) generated by LLMs. Running this code directly on your host or in standard containers can be risky.MicroVM-based Security
Unlike containers that share the host kernel, SmolVM uses KVM-backed microVMs. This provides:- Stronger Isolation: Hardware-level virtualization creates a significantly smaller attack surface compared to containers
- Hardware Boundaries: Each VM runs with its own kernel, making it significantly harder for malicious code to escape to the host
- Minimal Overhead: MicroVMs boot in sub-second time with minimal resource overhead
Agent-First Design
SmolVM abstracts away the complexity of microVM networking, storage, and TAP devices into a simple, pythonic API designed specifically for agent workflows.Architecture Components
SmolVM’s architecture consists of several key components:Core SDK (smolvm.vm.SmolVM)
The core orchestrator that manages:
- VM lifecycle (create, start, stop, delete)
- State management via SQLite
- Firecracker process management
- Network configuration
User Facade (smolvm.facade.VM)
The high-level, user-facing class that provides:
- Simple context manager support
- Auto-configuration for quick setup
- Reconnection to existing VMs
Network Layer (smolvm.network)
Manages Linux networking primitives:
- TAP device creation and configuration
- NAT rules via nftables
- Port forwarding (both SSH and application ports)
- IP address allocation
Storage Layer (smolvm.storage)
SQLite-backed state persistence:
- VM configuration and metadata
- Network assignments
- Process tracking
- Default location:
~/.local/state/smolvm/smolvm.db
API Client (smolvm.api)
Low-level client for Firecracker’s Unix socket API:
- Machine configuration
- Boot management
- Network interface attachment
Host Manager (smolvm.host)
Environment validation and setup:
- KVM support detection
- Firecracker binary management
- Prerequisites checking
VM Lifecycle
A typical SmolVM lifecycle follows this pattern:Using Context Manager
For automatic cleanup:Performance Characteristics
SmolVM is optimized for low-latency agent workflows. Latest lifecycle timings (p50) on a standard Linux host:| Phase | Time |
|---|---|
| Create + Start | ~572ms |
| SSH ready | ~2.1s |
| Command execution | ~43ms |
| Stop + Delete | ~751ms |
| Full lifecycle (boot → run → teardown) | ~3.5s |
Performance measured on AMD Ryzen 7 7800X3D (8C/16T), Ubuntu Linux, KVM/Firecracker backend.
Resource Management
Memory and CPU
Each VM can be configured with:- vCPUs: 1-32 virtual CPUs (default: 2)
- Memory: 128-16384 MiB (default: 512 MiB)
Disk Isolation
SmolVM defaults to isolated per-VM disks (disk_mode="isolated"), so each VM gets its own writable rootfs clone (sandbox-by-default).
Networking
Each VM receives:- Dedicated TAP device
- Private IP in
172.16.0.0/16range - Automatic NAT for outbound connectivity
- Isolated from other VMs
State Persistence
All VM state is stored in SQLite by default at:- Reconnect to running VMs
- Track resource allocation
- Persist VM configurations
Integration with AI Agents
Tool/Function Calling
Wrap SmolVM as a tool for your AI agent:Long-running Agent Environments
For agents that need to maintain state across multiple turns:Next Steps
- Learn about the Security Model
- Understand Backend Options
- Configure Networking