Loading...
Loading...
Sub-millisecond VM sandboxes for AI agents using copy-on-write KVM forking via Zeroboot
npx skill4agent add aradotso/trending-skills zeroboot-vm-sandboxSkill by ara.so — Daily 2026 Skills collection.
mmap(MAP_PRIVATE)Firecracker snapshot ──► mmap(MAP_PRIVATE) ──► KVM VM + restored CPU state
(copy-on-write) (~0.8ms)pip install zerobootnpm install @zeroboot/sdk
# or
pnpm add @zeroboot/sdkexport ZEROBOOT_API_KEY="zb_live_your_key_here"curl -X POST https://api.zeroboot.dev/v1/exec \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $ZEROBOOT_API_KEY" \
-d '{"code":"import numpy as np; print(np.random.rand(3))"}'import os
from zeroboot import Sandbox
# Initialize with API key from environment
sb = Sandbox(os.environ["ZEROBOOT_API_KEY"])
# Run Python code
result = sb.run("print(1 + 1)")
print(result) # "2"
# Run multi-line code
result = sb.run("""
import numpy as np
arr = np.arange(10)
print(arr.mean())
""")
print(result)import { Sandbox } from "@zeroboot/sdk";
const apiKey = process.env.ZEROBOOT_API_KEY!;
const sb = new Sandbox(apiKey);
// Run JavaScript/Node code
const result = await sb.run("console.log(1 + 1)");
console.log(result); // "2"
// Run async code
const output = await sb.run(`
const data = [1, 2, 3, 4, 5];
const sum = data.reduce((a, b) => a + b, 0);
console.log(sum / data.length);
`);
console.log(output);import os
from zeroboot import Sandbox
def execute_agent_code(code: str) -> dict:
"""Execute LLM-generated code in an isolated VM sandbox."""
sb = Sandbox(os.environ["ZEROBOOT_API_KEY"])
try:
result = sb.run(code)
return {"success": True, "output": result}
except Exception as e:
return {"success": False, "error": str(e)}
# Example: running agent-generated code safely
agent_code = """
import json
data = {"agent": "result", "value": 42}
print(json.dumps(data))
"""
response = execute_agent_code(agent_code)
print(response)import os
import asyncio
from zeroboot import Sandbox
async def run_sandbox(code: str, index: int) -> str:
sb = Sandbox(os.environ["ZEROBOOT_API_KEY"])
result = await asyncio.to_thread(sb.run, code)
return f"[{index}] {result}"
async def run_concurrent(snippets: list[str]):
tasks = [run_sandbox(code, i) for i, code in enumerate(snippets)]
results = await asyncio.gather(*tasks)
return results
# Run 10 sandboxes concurrently
codes = [f"print({i} ** 2)" for i in range(10)]
outputs = asyncio.run(run_concurrent(codes))
for out in outputs:
print(out)import { Sandbox } from "@zeroboot/sdk";
interface ExecutionResult {
success: boolean;
output?: string;
error?: string;
}
async function runInSandbox(code: string): Promise<ExecutionResult> {
const sb = new Sandbox(process.env.ZEROBOOT_API_KEY!);
try {
const output = await sb.run(code);
return { success: true, output };
} catch (err) {
return { success: false, error: String(err) };
}
}
// Integrate as a tool for an LLM agent
const tool = {
name: "execute_code",
description: "Run code in an isolated VM sandbox",
execute: async ({ code }: { code: string }) => runInSandbox(code),
};const API_BASE = "https://api.zeroboot.dev/v1";
async function execCode(code: string): Promise<string> {
const res = await fetch(`${API_BASE}/exec`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.ZEROBOOT_API_KEY}`,
},
body: JSON.stringify({ code }),
});
if (!res.ok) {
const err = await res.text();
throw new Error(`Zeroboot error ${res.status}: ${err}`);
}
const data = await res.json();
return data.output;
}curl https://api.zeroboot.dev/v1/healthPOST /v1/exec{
"code": "print('hello')"
}Authorization: Bearer <ZEROBOOT_API_KEY>
Content-Type: application/json{
"output": "hello\n",
"duration_ms": 0.79
}| Metric | Value |
|---|---|
| Spawn latency p50 | ~0.79ms |
| Spawn latency p99 | ~1.74ms |
| Memory per sandbox | ~265KB |
| Fork + exec Python | ~8ms |
| 1000 concurrent forks | ~815ms |
/dev/kvm# Check KVM availability
ls /dev/kvm
# Clone and build
git clone https://github.com/adammiribyan/zeroboot
cd zeroboot
cargo build --releasemmap(MAP_PRIVATE)/dev/kvm not found# Enable KVM kernel module
sudo modprobe kvm
sudo modprobe kvm_intel # or kvm_amdZEROBOOT_API_KEYzb_live_