Metrics, logs and usage
There are two sources:
- Inside the sandbox. The data plane’s
sandbox.metricsgives live CPU, memory and disk, once or as a stream. - From the API. The client reads a sandbox’s metrics and logs, including those of sandboxes that have ended.
from svm import Sandbox, SandboxClient
client = SandboxClient() # SVM_API_KEY and SVM_DOMAIN from the environment
with Sandbox.create(template="base", client=client) as sandbox: sandbox.commands.run("echo doing some work")
live = sandbox.metrics.get() # read inside the sandbox print(f"cpu {live.cpu_used_percent:.0f}% of {live.cpu_count}, " f"memory {live.mem_used_bytes >> 20}/{live.mem_total_bytes >> 20} MiB, " f"{live.process_count} processes")
samples = client.get_sandbox_metrics(sandbox.id) # from the control plane for point in samples["items"][-3:]: print(point)
logs = client.get_sandbox_logs(sandbox.id, page_size=20) for line in logs["items"]: print(line["timestamp"], line.get("stream", ""), line["line"])import { Sandbox, SandboxClient } from "@svm/sandbox";
const client = new SandboxClient();const sandbox = await Sandbox.create({ template: "base" }, client);try { await sandbox.commands.run("yes > /dev/null & sleep 2; kill %1");
// From inside the sandbox (envd): live figures. const live = await sandbox.metrics.get(); console.log(live.cpuUsedPercent, live.memUsedBytes, live.memTotalBytes, live.diskUsedBytes);
// From the control plane: metrics history and logs. console.log(await client.getSandboxMetrics(sandbox.id)); console.log(await client.getSandboxLogs(sandbox.id, { pageSize: 50 }));} finally { await sandbox.kill();}// Live numbers from inside the sandbox.metrics, err := sandbox.Metrics()if err != nil { return err}now, err := metrics.Get(ctx)if err != nil { return err}fmt.Printf("cpu %.1f%%, memory %d/%d bytes, disk %d/%d bytes\n", now.CPUUsedPercent, now.MemUsedBytes, now.MemTotalBytes, now.DiskUsedBytes, now.DiskTotalBytes)
// Control-plane metrics and logs, through the client.id := sandbox.Info().SandboxIDhistory, err := client.GetSandboxMetrics(ctx, id, svm.GetSandboxMetricsQuery{})if err != nil { return err}fmt.Println("metrics:", history)logs, err := client.GetSandboxLogs(ctx, id, svm.GetSandboxLogsQuery{})if err != nil { return err}fmt.Println("logs:", logs)require "svm"
client = SVM::Client.newbox = SVM::Sandbox.create(client: client, template: "base")begin box.commands.run("echo warming up; sleep 2")
live = box.metrics.get # from inside the guest puts "live: #{live.inspect}"
history = client.get_sandbox_metrics(box.id) # from the control plane puts "control plane: #{history.inspect}"
logs = client.get_sandbox_logs(box.id, page_size: 50) (logs["items"] || []).each { |line| puts line.inspect }ensure box.killendimport dev.svm.sandbox.Client;import dev.svm.sandbox.Sandbox;import java.util.Map;
public class MetricsLogsExample { public static void main(String[] args) { Client client = Client.fromEnvironment(); try (Sandbox sandbox = Sandbox.create(client, "base")) { sandbox.commands().run("echo some work");
// Live metrics from inside the sandbox (cpu, memory, disk, processes). Map<String, Object> live = sandbox.metrics().get(); System.out.println("cpu " + live.get("cpu_used_percent") + "%, mem " + live.get("mem_used_bytes"));
// Control-plane metrics and guest logs through the REST client. Map<String, Object> metrics = client.api().getSandboxMetrics(sandbox.id(), Map.of()); Map<String, Object> logs = client.api().getSandboxLogs(sandbox.id(), Map.of()); System.out.println("metrics: " + metrics); System.out.println("logs: " + logs); } }}client.get_usage(start=, end=, group_by=) returns billed usage in whole one-minute windows that begin at or after start and before
end. Pass minute-aligned times to see everything. complete_through in the answer says how far the meter has caught up.
From the CLI: svm sandbox metrics <id> and svm sandbox logs <id> --start 2026-11-01T00:00:00Z.