Sign in

Getting started

Quickstart

Create a sandbox, run code in it, run a shell command and destroy it. You need an API key and a terminal; the examples switch between cURL, Python and JavaScript.

  1. Get an API key

    Create a key on the API keys page of the dashboard. Keys start with ro_live_ and are shown once, so copy it before you close the dialog.

  2. Set your environment

    Every example on these pages reads the API URL and your key from the environment:

    Terminal
    export SPAWN_API_URL=https://dev-api.renderops.com
    export SPAWN_API_KEY=ro_live_...

    The Python examples use requests (pip install requests). The JavaScript examples use the built-in fetch in Node 18 or later.

  3. Create a sandbox

    The request returns once the microVM has booted and the agent inside it is ready, so you can use it straight away.

    curl -sS -X POST "$SPAWN_API_URL/session" \
      -H "Authorization: Bearer $SPAWN_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "quickstart",
        "size": "nano"
      }'
    Response 201 Created
    {
      "status": "success",
      "session": {
        "session_id": "3ecb0221-faf1-4976-a8ae-6fd6262de59a",
        "state": "active",
        ...
      }
    }

    Keep the session_id. For cURL, save it in a variable:

    export SANDBOX_ID=3ecb0221-faf1-4976-a8ae-6fd6262de59a
  4. Run some code

    Send source code and a language — python, node or bash. You get stdout, stderr and the exit code back.

    curl -sS -X POST "$SPAWN_API_URL/session/$SANDBOX_ID/run" \
      -H "Authorization: Bearer $SPAWN_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "language": "python",
        "code": "print(6 * 7)",
        "timeout": 10
      }'
    Response 200 OK
    {
      "status": "success",
      "result": {
        "stdout": "42\n",
        "stderr": "",
        "exit_code": 0,
        "termination_reason": "success",
        "duration_ms": 54.1,
        "guest_duration_ms": 17.8
      },
      ...
    }
  5. Run a shell command

    exec runs a command in the sandbox’s shell. Files you write stay on its disk for the next call.

    curl -sS -X POST "$SPAWN_API_URL/session/$SANDBOX_ID/exec" \
      -H "Authorization: Bearer $SPAWN_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "command": "echo hello > /tmp/hi.txt && cat /tmp/hi.txt",
        "timeout": 10
      }'
  6. Destroy it

    Destroying the sandbox deletes the VM and wipes its disk. It returns no body.

    curl -i -X DELETE "$SPAWN_API_URL/session/$SANDBOX_ID" \
      -H "Authorization: Bearer $SPAWN_API_KEY"
    Response 204 No Content

Next steps

Ctrl I