Install the agent framework extras before following these examples:This adds PydanticAI, OpenAI Agents SDK, LangChain, and Playwright as dependencies. See installation for details.
Why SmolVM for AI agents?
When AI agents generate and execute code, you need strong isolation to prevent:- Host compromise - Malicious code escaping to your system
- Data exfiltration - Unauthorized access to sensitive files
- Resource abuse - Uncontrolled CPU/memory/network usage
- Persistent side effects - State pollution across tasks
Hardware isolation
KVM-based virtualization provides stronger isolation than containers. Escape requires a hypervisor exploit, not just a kernel vulnerability.
Controlled networking
Fine-grained control over guest internet access. Restrict or monitor all network traffic.
Ephemeral environments
Spin up a fresh VM for every task and destroy immediately after. No persistent state between tasks.
Resource limits
Strict CPU and memory limits prevent resource exhaustion attacks.
Agentor
Agentor is Celesto’s own agent framework. It has built-in SmolVM support throughSmolVMRuntime, so your agent’s shell commands run inside a sandbox automatically — no glue code needed.
Pass SmolVMRuntime as the executor for ShellTool and Agentor routes every command through a dedicated microVM:
SmolVMRuntime manages the VM lifecycle for you. When the agent calls the shell tool, the command runs inside the microVM instead of on your host. Call runtime.close() when you are done to tear down the sandbox.
When to use Agentor vs. other frameworks
Use Agentor when you want the simplest path to a sandboxed agent — one import for the runtime, one for the tool, and you are done. If you already use PydanticAI, OpenAI Agents, or LangChain, keep reading for framework-specific patterns below.PydanticAI
Register SmolVM as a PydanticAI tool so the agent can run shell commands inside an ephemeral sandbox. Each call spins up a fresh VM, runs the command, and tears it down automatically.Reusable sandbox across turns
If your agent needs to maintain state between tool calls (for example, writing a file in one turn and reading it in the next), keep the VM alive across invocations. The helper functions below create the sandbox on first use and reconnect on subsequent calls:OpenAI Agents SDK
Use SmolVM as a function tool in the OpenAI Agents SDK:LangChain
Wrap SmolVM as a LangChain tool:Browser sessions
SmolVM includes a built-inBrowserSession class that launches a Chromium browser inside a microVM. You can use it for web scraping, testing, and computer-use agents that need to interact with real web pages in an isolated environment.
Browser session modes
| Mode | Description |
|---|---|
headless | No visual output. Good for automated scraping and testing. |
live | Exposes a noVNC live-view URL so you can watch the browser in real time. |
Browser session configuration
BrowserSessionConfig accepts these options:
| Parameter | Type | Default | Description |
|---|---|---|---|
mode | "headless" | "live" | "headless" | Display mode. live enables noVNC. |
viewport | {"width": int, "height": int} | 1280 x 720 | Browser viewport size. |
record_video | bool | False | Record a video (requires mode="live"). |
profile_mode | "ephemeral" | "persistent" | "ephemeral" | Whether to reuse browser state across sessions. |
profile_id | str | — | Required when profile_mode="persistent". |
timeout_minutes | int | 30 | Auto-shutdown timer (1-240 minutes). |
allow_downloads | bool | True | Allow file downloads in the browser. |
env_vars | dict[str, str] | {} | Environment variables injected into the guest. |
mem_size_mib | int | 2048 | Guest memory in MiB (512-16384). |
disk_size_mib | int | 4096 | Root filesystem size in MiB (2048-16384). |
Computer-use with OpenAI
CombineBrowserSession with OpenAI’s computer-use API for autonomous web browsing agents. The model sees the browser through screenshots and sends back click, type, and scroll instructions.
You provide a task and an optional starting URL. SmolVM launches a browser in an isolated sandbox, and the model drives it step by step until the task is complete.
PydanticAI with agent-browser
You can let a PydanticAI agent drive a SmolVM browser session through theagent-browser CLI instead of using Playwright directly. The agent runs host-side shell commands — starting the browser, taking snapshots, clicking elements, and capturing screenshots — all through a single run_host_bash tool.
This approach is useful when you want the LLM to decide what to do in the browser step by step, without writing Playwright code yourself.
Here is how the pieces fit together:
Prerequisites:
- The agent calls
smolvm browser start --live --jsonto launch an isolated browser session. - SmolVM returns a JSON payload with a
session_id, acdp_url(including the localhost port), and alive_url. - The agent reads
agent-browser --help, then usesagent-browser --cdp <cdp_port>commands to take snapshots, click elements, and navigate pages. - The agent can save screenshots and collect artifacts along the way.
- When finished, the agent calls
smolvm browser stop <session_id>to tear down the session.
agent-browser --help to learn the available commands, plans its steps, takes snapshots (with --json output) to understand page structure, and picks elements by reference ID.
Generic tool pattern
If you use a framework not listed above, the core pattern is the same. Define a function that creates aSmolVM, runs a command, and returns the output:
Long-running agent environments
For agents that need to maintain state across multiple interactions without using a reusable tool pattern:Best practices
Use ephemeral VMs for untrusted code
Always set timeouts
Inject secrets via environment variables
Set resource limits
Error handling
Next steps
Basic usage
Learn fundamental SmolVM operations
Custom images
Build specialized images for your agents
Environment variables
Configure agent environments dynamically
Port forwarding
Expose agent services to your host