SPAWNBOX

● Works today

Run the code your model writes.One tool call, one sandbox.

Give your chat model or workflow a run-code tool. Each call runs in its own microVM on your servers, and you get back stdout, stderr and the exit code. The code cannot reach your app, your keys or your network.

Any language you install in the template

  • Python
  • Node.js
  • TypeScript
  • Bun
  • Deno
  • Go
  • Rust
  • Ruby
  • Bash
CHAT MODELSANDBOXpython3 main.pySPAWNBOX APIKEYS · SITE RULESYOUR SERVER
FIG. 01 · ONE REQUEST, THERE AND BACK
0103

Follow one request.

Each step shows the call, the reply and the lines it adds to the activity log. You can read the whole log withGET /v1/sandboxes/$S/events.

  1. YOUR APP

    The model calls your tool

    Your chat app or workflow engine gets a tool call with code in it. Treat that code as untrusted. The model wrote it, and a user's prompt can steer the model.

    TOOL CALL
    {
      "type": "tool_use",
      "id": "call_7f3",
      "name": "run_python",
      "input": {
        "code": "import pandas as pd\ndf = pd.read_csv('sales.csv')\nprint(df.groupby('region').total.sum())"
      }
    }
  2. SPAWNBOX API

    Your app gets a sandbox

    py is a template you build once, with Python and pandas. Send the tool call ID in X-Spawnbox-Step. The events of the request get this ID, so you can find them later with ?step_id=. With a warm pool, the sandbox is ready in about 8 ms. This one cannot reach the internet.

    REQUEST
    POST /v1/sandboxes
    X-Spawnbox-Step: call_7f3
    
    {"template": "py", "timeout_s": 3600,
     "egress": {"mode": "deny_all"}}
    • sandbox.createdsbx_c7mty9fysaf0t3d5
  3. SPAWNBOX API

    Put the code and its data in

    Write each file with one request. A relative path starts at /workspace. Spawnbox replaces a file only after it gets the full body.

    REQUEST
    PUT /v1/sandboxes/$S/files?path=main.py
    PUT /v1/sandboxes/$S/files?path=sales.csv
    • file.written/workspace/main.py
    • file.written/workspace/sales.csv
  4. IN THE SANDBOX

    Run it

    Set a time limit, so a loop cannot run forever. If the code tries to reach a website, the DNS answer is REFUSED and the log keeps a record.

    REQUEST
    POST /v1/sandboxes/$S/exec
    X-Spawnbox-Step: call_7f3
    
    {"cmd": "python3 main.py", "timeout_s": 30}
    RESPONSE
    {"stdout": "region\neu    18240\nus    31977\n...",
     "stderr": "", "exit_code": 0,
     "timed_out": false, "duration_ms": 412}
    • exec.startedpython3 main.py
    • exec.finishedexit 0
  5. YOUR APP

    Send the result back to the model

    Return stdout as the tool result, or stderr and the exit code if it failed. Keep the sandbox for the next turn of the chat: its files stay. After 10 minutes with no requests, it pauses by itself and frees its CPU and memory. The next request wakes it in about 65 ms. Spawnbox deletes it when its timeout_s ends. Paused time does not count.

    TOOL RESULT
    {
      "type": "tool_result",
      "tool_use_id": "call_7f3",
      "content": "region\neu    18240\nus    31977\n..."
    }
    • sandbox.pausedidle
0203

In a workflow

Tag each step

Send the step ID with each request. Later, get all the events of that step.

GET /v1/events?step_id=report.3

Try three ways from one point

Copy a running sandbox with its memory, processes and files. Up to 16 copies in less than 1 s.

POST /v1/sandboxes/$S:fork

{"count": 3}

Keep the output

Mount a volume. Its files stay after the sandbox is deleted, for the next step to use.

"volumes": [{"volume": "reports",
             "path": "/data"}]
0303

Good to know.