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.
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.Set your environment
Every example on these pages reads the API URL and your key from the environment:
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-infetchin Node 18 or later.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" }'{ "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-6fd6262de59aRun some code
Send source code and a language —
python,nodeorbash. 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 }'{ "status": "success", "result": { "stdout": "42\n", "stderr": "", "exit_code": 0, "termination_reason": "success", "duration_ms": 54.1, "guest_duration_ms": 17.8 }, ... }Run a shell command
execruns 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 }'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"