Sandboxes
Create, inspect, extend, find, kill
Section titled “Create, inspect, extend, find, kill”from svm import Sandbox
sandbox = Sandbox.create( template="base", cpu_count=2, memory_mb=1024, timeout_seconds=600, metadata={"project": "docs", "step": "lifecycle"},)try: info = sandbox.get_info() print(info.sandbox_id, info.state, "ends at", info.end_at)
sandbox.set_timeout(1800) # 30 minutes from now
page = Sandbox.list(state=Sandbox.LIVE_STATES, metadata={"project": "docs"}) for found in page.items: print("found", found.id, found.state)
same = Sandbox.connect(sandbox.id) # a second handle, e.g. from another process print(same.commands.run("uptime").stdout)finally: sandbox.kill()import { Sandbox } from "@svm/sandbox";
const sandbox = await Sandbox.create({ template: "base", cpuCount: 2, memoryMb: 1024, timeoutSeconds: 300, metadata: { app: "docs", user: "alice" },});try { const info = await sandbox.getInfo(); console.log(info.state, info.templateId, info.endAt);
await sandbox.setTimeout(600); // ten more minutes from now
const page = await Sandbox.list({ metadata: { app: "docs" }, state: "running" }); for (const s of page.items) console.log(s.id, s.state);
const again = await Sandbox.connect(sandbox.id); // a second handle to the same sandbox console.log((await again.commands.run("hostname")).stdout);} finally { await sandbox.kill();}sandbox, err := client.CreateSandbox(ctx, svm.CreateSandboxOptions{ Template: "base", CPUCount: 2, MemoryMB: 1024, TimeoutSeconds: 600, Metadata: map[string]string{"project": "docs"},})if err != nil { return err}defer sandbox.Kill(ctx)
if _, err := sandbox.SetTimeout(ctx, 1800); err != nil { // extend to 30 minutes from now return err}info, err := sandbox.GetInfo(ctx)if err != nil { return err}fmt.Println(info.SandboxID, info.State, "ends at", info.EndAt)
page, err := client.ListSandboxes(ctx, svm.ListSandboxOptions{Metadata: map[string]string{"project": "docs"}})if err != nil { return err}for _, item := range page.Items { fmt.Println("listed", item.SandboxID, item.State)}
again, err := client.ConnectSandbox(ctx, info.SandboxID, svm.ConnectSandboxOptions{})if err != nil { return err}defer again.CloseTransports() // closes this handle's connections; it does not kill the sandboxfmt.Println("reconnected to", again.Info().SandboxID)
existed, err := sandbox.Kill(ctx)fmt.Println("killed:", existed)require "svm"
client = SVM::Client.newbox = SVM::Sandbox.create(client: client, template: "base", cpu_count: 2, memory_mb: 1024, timeout_seconds: 300, metadata: { "user" => "alice" })begin info = box.get_info puts "#{info['sandbox_id']} #{info['state']} until #{info['end_at']}"
box.set_timeout(600) # ten more minutes from now
page = SVM::Sandbox.list(client: client, metadata: { "user" => "alice" }) page[:items].each { |s| puts "#{s.id} #{s.state}" }
again = SVM::Sandbox.connect(box.id, client: client) puts again.commands.run("uptime").stdoutensure box.killendimport dev.svm.sandbox.Client;import dev.svm.sandbox.Sandbox;import java.util.Map;
public class SandboxLifecycleExample { public static void main(String[] args) { Client client = Client.fromEnvironment();
Sandbox.CreateOptions options = new Sandbox.CreateOptions(); options.template = "base"; options.cpuCount = 2; options.memoryMb = 1024; options.timeoutSeconds = 300; options.metadata = Map.of("project", "docs"); options.wait = true;
try (Sandbox sandbox = Sandbox.create(client, options)) { Map<String, Object> info = sandbox.getInfo(); System.out.println(sandbox.id() + " is " + info.get("state"));
sandbox.setTimeout(600); // ten more minutes from now
for (Sandbox s : Sandbox.list(client, "running", null, Map.of("project", "docs"), 0)) { System.out.println("found " + s.id()); }
Sandbox again = Sandbox.connect(client, sandbox.id()); System.out.println("second handle: " + again.id() + " " + again.state()); } }}Create options
Section titled “Create options”| Option | Default | Notes |
|---|---|---|
template |
base |
A catalog template, or one you built. See Templates. |
cpu_count, memory_mb |
the template’s | Billed while the sandbox runs. |
disk_mb |
the template’s root size | The disk is grown as the sandbox starts. Give a template that installs packages room to work. |
timeout_seconds |
300 | Lifetime from now, capped by your plan (at most 7 days). |
metadata |
none | String pairs. list filters on them. |
envs |
none | Environment variables for every command. |
lifecycle |
kill at timeout | on_timeout: pause keeps it. auto_resume controls whether traffic wakes a paused sandbox. See Persistence. |
secure |
true | Public URLs need the traffic access token. See Networking. |
mcp_servers |
none | Catalog MCP servers to turn on. See Agent tools. |
Reconnecting
Section titled “Reconnecting”Any process with the id can connect. It fetches fresh data-plane access, and it resumes the sandbox first if it was paused.
connect returns once the sandbox runs; pass wait=False (in your SDK’s spelling) to return as soon as the resume is accepted.
list returns one page with items and a next_page_token. Listed sandboxes carry no access credentials, so connect to one
before you use it.
Templates you can always use
Section titled “Templates you can always use”base is always there, even when your team has built nothing, and even though a template list does not include it. It carries Python,
Node.js, git, gh, tmux, ripgrep, jq and a compiler. The language templates (python, node, go) are slim. For example, python has
no ps, so use commands.list() to look for processes.