Skip to content

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.

  1. Get an API key. Sign in to the SVM console and create a key under API keys.

  2. 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'
  3. Run code in a sandbox.

    from svm import Sandbox
    from 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.

    run_code runs in a Jupyter-style kernel, so variables defined in one call stay defined in the next. The code-interpreter-all template has the kernels. commands.run runs a shell command and returns its exit code, stdout and stderr.

  4. 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.