Quickstart
A sandbox is a small Linux microVM that starts in milliseconds and is isolated from everything else, including other sandboxes. You create one through the API, run code and commands in it, and kill it when you are done.
-
Get an API key. Sign in to the SVM console and create a key under API keys.
-
Install an SDK and set your credentials. The install page has the details for each language.
Terminal window export SVM_API_KEY='…'export SVM_DOMAIN='api.example.com' -
Run code in a sandbox.
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) # 42result = 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 mainimport ("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_DOMAINif 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")beginexecution = box.run_code("x = 21\nx * 2")puts execution.text # 42result = box.commands.run("echo hello from $(hostname)")puts result.stdoutensurebox.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());}}}run_coderuns in a Jupyter-style kernel, so variables defined in one call stay defined in the next. Thecode-interpreter-alltemplate has the kernels.commands.runruns a shell command and returns its exit code, stdout and stderr. -
Kill the sandbox when you are done, as the sample does. A sandbox you forget is ended at its timeout (5 minutes unless you set one), or paused if you asked for that. See Persistence.