AI Agents

Use Spunto sandboxes as isolated machines for AI coding agents — or hand them whole tasks.

Spunto gives an agent two ways in:

  • Tasks — you hand Spunto a prompt and it runs the agent for you (Claude Code, Codex or Mistral Vibe) in a sandbox of its own, and stops at review. → Tasks
  • Sandboxes — your own agent loop drives a machine over the REST API: create it from a project, run commands in it, attach to a terminal, read its ports, destroy it. This page is about that.

  • Isolation — each agent run gets its own machine; no access to the host
  • Pre-configured — repos are cloned, secrets are injected, your lifecycle commands have run
  • Disposable — destroy it when done, or keep it stopped with its /workspace
  • API-driven — create, run, read and destroy entirely over HTTP

1. POST   /api/orgs/{orgId}/sandboxes                     → create it from a project
2. GET    /api/orgs/{orgId}/sandboxes/{sandboxId}         → wait for status "running"
3. POST   /api/orgs/{orgId}/sandboxes/{sandboxId}/exec    → run commands (or attach a terminal)
4. DELETE /api/orgs/{orgId}/sandboxes/{sandboxId}         → destroy it

Create an API key in the organization the agent should operate in — Settings → API keys — with workers:read + workers:write (they cover sandboxes) and workers:exec to run commands or open a terminal; add projects:read if it also looks projects up. For an agent deployed long-term outside any one person's account, create an org-owned (service account) key — it keeps working if its creator leaves.

curl -H "Authorization: Bearer spk_..." \
  https://spunto.net/api/orgs/{orgId}/projects

Both appId and machineType are optional: without them, the organization's default sandbox (Spunto Cloud unless changed) at its default machine type. GET /api/orgs/{orgId}/sandboxes/providers lists the machine types (standard/small, standard/default…):

curl -X POST \
  -H "Authorization: Bearer spk_..." \
  -H "Content-Type: application/json" \
  -d '{ "projectId": "{projectId}", "machineType": "standard/default", "branch": "main" }' \
  https://spunto.net/api/orgs/{orgId}/sandboxes

The answer comes back straight away, with status: "starting". Poll GET .../sandboxes/{sandboxId} until status === "running" (or error, with statusReason).

curl -X POST \
  -H "Authorization: Bearer spk_..." -H "Content-Type: application/json" \
  -d '{ "command": "npm test" }' \
  https://spunto.net/api/orgs/{orgId}/sandboxes/{sandboxId}/exec

It waits for the command and answers with its exit code and output:

{
  "exitCode": 0,
  "timedOut": false,
  "stdout": "…",
  "stderr": "",
  "truncated": false,
  "durationMs": 5120
}

The command runs with the sandbox's shell (bash -lc) in /workspace, so its PATH, tool versions and secrets apply. Pass cwd to run elsewhere, env to add variables, and timeoutMs (up to 30 minutes). Only the sandbox's owner can run commands in it.

For a real shell — feeding input to a program, or a session a human can watch — the sandbox terminal is a full PTY over a WebSocket. It accepts the same Authorization: Bearer <api key> header (scope workers:exec), so no browser session is needed.

wss://spunto.net/api/sandboxes/{sandboxId}/terminal?mode=terminal&cols=220&rows=50&session=main
Query paramDefaultDescription
modeterminalterminal (interactive PTY) or logs (the sandbox's logs, read-only)
cols / rows120 / 30PTY dimensions — a wide value avoids line-wrapping in agent output
sessionmainPersistent session name — reuse it to reattach to a running session

Protocol:

  1. Wait for { "type": "ready" } — the PTY is attached
  2. Send { "type": "input", "data": "<base64>" } — raw keystrokes, including \r to submit a line
  3. Receive { "type": "output", "data": "<base64>" } — raw PTY output (ANSI included)
  4. Send { "type": "resize", "cols": N, "rows": M } to resize the PTY

Reconnecting with the same ?session=<name> reattaches the session — the shell and what runs in it survive a disconnect. That's the way to run a long agent command without keeping the connection open for its whole duration.

import WebSocket from "ws"
import { Buffer } from "node:buffer"
 
const ws = new WebSocket(
  `wss://spunto.net/api/sandboxes/${sandboxId}/terminal?mode=terminal&cols=220&rows=50`,
  { headers: { Authorization: `Bearer ${apiKey}` } }
)
 
ws.once("message", (raw) => {
  if (JSON.parse(raw.toString()).type !== "ready") return
  ws.send(JSON.stringify({ type: "input", data: Buffer.from("npm run build\r").toString("base64") }))
})
 
ws.on("message", (raw) => {
  const msg = JSON.parse(raw.toString())
  if (msg.type === "output") process.stdout.write(Buffer.from(msg.data, "base64"))
})

curl -H "Authorization: Bearer spk_..." \
  https://spunto.net/api/orgs/{orgId}/sandboxes/{sandboxId}/ports

Returns the IDE's URL and every port listening in the sandbox, each on its own HTTPS URL.

Secrets of the organization, of the project and of the member are injected as environment variables into every sandbox — e.g. a personal one:

curl -X POST \
  -H "Authorization: Bearer spk_..." \
  -H "Content-Type: application/json" \
  -d '{ "name": "ANTHROPIC_API_KEY", "value": "sk-ant-..." }' \
  https://spunto.net/api/users/me/secrets

Encrypted at rest, never returned by the API.

Tip

Don't want to write the loop at all? POST /api/orgs/{orgId}/projects/{projectId}/tasks with a prompt does all of the above for you — a sandbox, an agent session you watch live, and a review at the end. See Tasks.