Skip to content

SDK operations cookbook

Use this page when you want a practical SDK operation and need to know whether to call the SDK today, use the CLI directly, or treat the helper as target API.

The shipped SDK runtime surface is intentionally smaller than the product target. Current examples use Sandbox.create(...), commands.start(...), files.write(...), TTLs, resources, network declarations, record mode, live mode, and cleanup. Higher-level helpers such as commands.run(...), files.read(...), logs, ports, and snapshots are parity targets until the language SDK tests prove them.

OperationPython todayTypeScript todaySecure fallback today
Create sandbox recordingmvm.Sandbox.create(...)Sandbox.create(...)mvmctl compile or mvmctl run --mode plan
Create live sandboxmvmctl run --mode live ./script.pymvmctl run --mode live ./script.tsmvmctl up
Start commandsandbox.commands.start([...])sandbox.commands.start([...])mvmctl proc start or mvmctl exec
Capture command resultTarget commands.run(...)Target commands.run(...)CLI command result and receipt paths
Write filesandbox.files.write(path, data)sandbox.files.write(path, data)mvmctl fs write
Read/list/remove fileTarget helpersTarget helpersmvmctl fs read, mvmctl fs ls, mvmctl fs rm
LogsTarget helperTarget helpermvmctl logs
PortsTarget helperTarget helperport-forwarding CLI commands
Pause/resumeTarget helperTarget helpermvmctl pause, mvmctl resume
Snapshot save/restoreTarget helperTarget helpermvmctl snapshot save, mvmctl snapshot restore
Stop cleanupcontext manager or kill()using/Symbol.dispose or kill()mvmctl down
import mvm
with mvm.Sandbox.create(
"python-3.12",
workload_id="agent-tool",
ttl="30m",
include=["src"],
resources=mvm.resources(cpu_cores=1, memory_mb=512, rootfs_size_mb=1024),
network=mvm.network(mode="deny"),
) as sandbox:
sandbox.files.write("/app/main.py", "print('hello from mvm')")
sandbox.commands.start(
["python", "/app/main.py"],
env={"MODE": "dev", "API_KEY": mvm.secret("api-key")},
)

Security notes:

  • the Python script itself runs on the host in record, plan, and live modes;
  • secret references are recorded as references, not copied as raw values;
  • commands.start(...) starts work, but result capture is still a parity target;
  • the context manager records or performs cleanup through kill().

Run modes:

Terminal window
mvmctl compile ./sandbox.py --out /tmp/sandbox-ir
mvmctl run --mode plan ./sandbox.py
mvmctl run --mode live ./sandbox.py

The product target is a typed result helper:

result = sandbox.commands.run(["python", "/app/main.py"], timeout_seconds=30)
print(result.exit_code)
print(result.stdout)
print(result.audit_id)

Until this helper is shipped in a language SDK, use the CLI path for result capture, receipts, and automation that needs exit status or bounded output.

The product target is a symmetric file API:

sandbox.files.write("/work/input.json", b"{}")
data = sandbox.files.read("/work/output.json")
entries = sandbox.files.list("/work")
sandbox.files.remove("/work/output.json")

Until read/list/remove helpers are shipped, use the CLI filesystem commands. Treat bytes returned from the guest as untrusted and possibly sensitive.

Logs and ports should keep policy visible:

for event in sandbox.logs(follow=True, redact=True):
print(event.message)
forward = sandbox.ports.forward(host="127.0.0.1", host_port=8080, guest_port=8000)

Until language helpers are shipped, use the CLI logging and port-forwarding commands. Bind host ports explicitly and avoid wildcard listeners unless the workflow requires them.

Lifecycle helpers should expose the same state model as the CLI:

snapshot = sandbox.snapshot(name="after-index")
sandbox.pause()
sandbox.resume(snapshot=snapshot.id)
sandbox.stop()
sandbox.destroy()

Until those helpers are shipped, use:

Terminal window
mvmctl pause agent-sandbox
mvmctl resume agent-sandbox
mvmctl snapshot save agent-sandbox after-index
mvmctl snapshot restore agent-sandbox after-index
mvmctl down agent-sandbox

Snapshots and cold state can contain memory, files, process state, and credentials. Retention and deletion policy should be explicit in automation.