Run untrusted code in ephemeral microVM sandboxes
Lease hardware-isolated microVM sandboxes (/v1/sandbox/lease), execute untrusted code safely, inspect files, and reclaim quota cleanly.
Never run agent-generated code on your host kernel or shared build runner. /v1/sandbox leases fast, hardware-isolated microVMs for every untrusted build, test run, or evaluation harness.
Architecture & contract
Each sandbox has an isolated filesystem (/v1/sandbox/{id}/fs), exec interface (/v1/sandbox/{id}/exec), optional preview ports, and automatic TTL teardown so leaked processes cannot outlive a run.
Primary endpoint: POST /v1/sandbox/lease · Status: shipped · Level: practitioner
Run it across all four surfaces
CLI
SDK
HTTP
MCP
hanzo sandbox quota
SANDBOX_ID=$(hanzo sandbox lease --data '{"image":"node:22-alpine","ttl_seconds":300}' | jq -r '.id')
hanzo sandbox exec "$SANDBOX_ID" --data '{"cmd":["node","-v"]}'
hanzo sandbox stop --data "{"id":"${SANDBOX_ID}"}"TypeScript
Python
import { Configuration, SandboxApi } from 'hanzoai';
const sb = new SandboxApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data: lease } = await sb.postSandboxLease({ image: 'node:22-alpine', ttl_seconds: 300 });
try {
const { data: res } = await sb.postSandboxByIdExec(lease.id, { cmd: ['node', '-v'] });
console.log(res);
} finally {
await sb.postSandboxStop({ id: lease.id });
}import os
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import SandboxApi
api = SandboxApi(ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"])))
lease = api.post_sandbox_lease({"image": "node:22-alpine", "ttl_seconds": 300})
try:
print(api.post_sandbox_by_id_exec(lease["id"], {"cmd": ["node", "-v"]}))
finally:
api.post_sandbox_stop({"id": lease["id"]})SANDBOX_ID=$(curl -s -X POST https://api.hanzo.ai/v1/sandbox/lease \
-H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
-d '{"image":"node:22-alpine","ttl_seconds":300}' | jq -r '.id')
curl -s -X POST "https://api.hanzo.ai/v1/sandbox/${SANDBOX_ID}/exec" \
-H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
-d '{"cmd":["node","-v"]}' | jq '.'
curl -s -X POST https://api.hanzo.ai/v1/sandbox/stop \
-H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
-d "{"id":"${SANDBOX_ID}"}"curl -s -X POST https://api.hanzo.ai/v1/mcp \
-H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "sandbox",
"arguments": {"op": "get_sandbox_quota", "input": {}}
}
}'Verify the outcome
- Confirm stdout prints the expected Node version and
stopreturns HTTP 200.
Production guardrails
- Never pass long-lived
sk-admin keys into sandbox environment variables; inject only short-lived scoped tokens when strictly needed.
Next steps & Hanzo University
Was this page useful?
Broken link or missing step? Drop it in #docs on Discord or open a PR.PreviousManage GPU clusters and BYO compute fleetsNextConnect private services over /v1/network zero-trust mesh
Last updated Nov 25, 2026