Python
pip install svm · package svmPick a language once; every code sample on the site follows it.
from svm import Sandboxfrom svm.code_interpreter import CODE_INTERPRETER_TEMPLATE # "code-interpreter-all"
# run_code needs a template with the code interpreter kernel.with Sandbox.create(template=CODE_INTERPRETER_TEMPLATE) as sandbox: execution = sandbox.run_code("x = 21\nx * 2") print(execution.text) # 42
result = sandbox.commands.run("echo hello from $(hostname)") print(result.stdout)# Leaving the block kills the sandbox.import { Sandbox } from "@svm/sandbox";
// Reads SVM_API_KEY and SVM_DOMAIN from the environment.const sandbox = await Sandbox.create({ template: "code-interpreter-all", wait: true });try { const execution = await sandbox.runCode("print('hello from python')\n6 * 7"); console.log(execution.logs.stdout.join("")); console.log(execution.text); // "42"
const result = await sandbox.commands.run("uname -a"); console.log(result.stdout);} finally { await sandbox.kill();}package main
import ( "context" "fmt" "log" "strings"
svm "github.com/jupimartofficial-cell/icloud/firecracker-agent-platform/sdk/go")
func main() { if err := run(context.Background()); err != nil { log.Fatal(err) }}
func run(ctx context.Context) error { client, err := svm.NewClient(svm.ClientOptions{}) // reads SVM_API_KEY and SVM_DOMAIN if err != nil { return err } // RunCode needs a template with the kernel: svm.CodeInterpreterTemplate is "code-interpreter-all". sandbox, err := client.CreateSandbox(ctx, svm.CreateSandboxOptions{Template: svm.CodeInterpreterTemplate}) if err != nil { return err } defer sandbox.Kill(ctx)
execution, err := sandbox.RunCode(ctx, "x = 6 * 7\nprint('x is', x)") if err != nil { return err } fmt.Print(strings.Join(execution.Logs.Stdout, ""))
commands, err := sandbox.Commands() if err != nil { return err } result, err := commands.Run(ctx, "echo hello from $(hostname)", svm.RunOptions{}) if err != nil { return err } fmt.Print(string(result.Stdout)) return nil}require "svm"
# Reads SVM_API_KEY and SVM_DOMAIN from the environment.box = SVM::Sandbox.create(template: "code-interpreter-all")begin execution = box.run_code("x = 21\nx * 2") puts execution.text # 42
result = box.commands.run("echo hello from $(hostname)") puts result.stdoutensure box.killendimport dev.svm.sandbox.Client;import dev.svm.sandbox.Execution;import dev.svm.sandbox.ProcessResult;import dev.svm.sandbox.Sandbox;
public class QuickstartExample { public static void main(String[] args) { // Reads SVM_API_KEY and SVM_DOMAIN from the environment. Client client = Client.fromEnvironment();
// The code interpreter needs the "code-interpreter-all" template; close() kills the sandbox. try (Sandbox sandbox = Sandbox.create(client, "code-interpreter-all")) { Execution execution = sandbox.runCode("print('hello from python')\n1 + 1"); System.out.print(String.join("", execution.logs.stdout)); System.out.println("result: " + execution.text());
ProcessResult result = sandbox.commands().run("echo hello from the shell"); System.out.print(result.stdout()); } }}Python
pip install svm · package svmTypeScript
npm install @svm/sandboxGo
go get …/firecracker-agent-platform/sdk/goRuby
gem install svmJava
dev.svm:sandboxCLI
svm · ships with the Python packageEvery SDK exposes the same methods under its own naming conventions. The SDK reference shows each method in all five languages side by side, generated from the SDK sources.