Overview
Build with Spaceyard
Give your agent a computer: start a Linux or Windows desktop in seconds, run commands on it and use it like a person.
Introduction
A sandbox is a cloud computer for an agent: a Linux or Windows machine with a full desktop, a browser and a shell, started in seconds and billed by the minute. Your agent runs commands on it, and through computer use it sees the screen and clicks, types and scrolls like a person.
The API covers a sandbox's whole life: create it, run commands on it, use its desktop, stop it and destroy it. It takes and returns JSON, at one address:
https://api.spaceyard.dev/v1 Quickstart
- Create an account and add credit. A new account adds at least €10 before its first sandbox.
- Make an API key on the console's API key page, and keep it in an environment variable,
SPACEYARD_API_KEY. - Start a sandbox, run a command on it, look at its screen, and destroy it:
# 1. Pick an image: its id, and whether your account may start it.
curl https://api.spaceyard.dev/v1/sandboxes/images \
-H "Authorization: Bearer $SPACEYARD_API_KEY"
# 2. Start a sandbox from it.
curl -X POST https://api.spaceyard.dev/v1/sandboxes \
-H "Authorization: Bearer $SPACEYARD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"image_id": 1}'
# 3. Ask again until its status is "running".
curl https://api.spaceyard.dev/v1/sandboxes/7f3c2a10-5b1e-4c2d-9a7e-2f1d8c4b6e90 \
-H "Authorization: Bearer $SPACEYARD_API_KEY"
# 4. Run a command on it.
curl -X POST https://api.spaceyard.dev/v1/sandboxes/7f3c2a10-5b1e-4c2d-9a7e-2f1d8c4b6e90/exec \
-H "Authorization: Bearer $SPACEYARD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"command": "uname -a"}'
# 5. Look at its screen.
curl -X POST https://api.spaceyard.dev/v1/sandboxes/7f3c2a10-5b1e-4c2d-9a7e-2f1d8c4b6e90/computer \
-H "Authorization: Bearer $SPACEYARD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"action": "screenshot"}'
# 6. Destroy it when you are done.
curl -X DELETE https://api.spaceyard.dev/v1/sandboxes/7f3c2a10-5b1e-4c2d-9a7e-2f1d8c4b6e90 \
-H "Authorization: Bearer $SPACEYARD_API_KEY" import base64
import os
import time
import requests
API = "https://api.spaceyard.dev/v1"
headers = {"Authorization": f"Bearer {os.environ['SPACEYARD_API_KEY']}"}
# 1. Pick a Linux desktop your account may start.
images = requests.get(f"{API}/sandboxes/images", headers=headers).json()["data"]
image = next(i for i in images if i["os"] == "linux" and i["desktop"] and i["allowed"] and i["in_stock"])
# 2. Start a sandbox from it.
sandbox = requests.post(f"{API}/sandboxes", headers=headers, json={"image_id": image["id"]}).json()["data"]
try:
# 3. Wait until it runs.
while sandbox["status"] != "running":
if sandbox["status"] == "failed":
raise RuntimeError(sandbox["error"])
time.sleep(2)
sandbox = requests.get(f"{API}/sandboxes/{sandbox['uuid']}", headers=headers).json()["data"]
# 4. Run a command on it.
result = requests.post(
f"{API}/sandboxes/{sandbox['uuid']}/exec", headers=headers, json={"command": "uname -a"}
).json()["data"]
print(result["exit_code"], result["stdout"])
# 5. Look at its screen.
shot = requests.post(
f"{API}/sandboxes/{sandbox['uuid']}/computer", headers=headers, json={"action": "screenshot"}
).json()["data"]
with open("screen.jpg", "wb") as file:
file.write(base64.b64decode(shot["image"]))
finally:
# 6. Destroy it, whatever happened: it is billed while it exists.
requests.delete(f"{API}/sandboxes/{sandbox['uuid']}", headers=headers) import { writeFile } from "node:fs/promises";
const API = "https://api.spaceyard.dev/v1";
const headers = {
Authorization: `Bearer ${process.env.SPACEYARD_API_KEY}`,
"Content-Type": "application/json",
};
const call = async (method, path, body) => {
const response = await fetch(API + path, { method, headers, body: body && JSON.stringify(body) });
const json = await response.json();
if (!response.ok) throw new Error(json.error.message);
return json.data;
};
// 1. Pick a Linux desktop your account may start.
const images = await call("GET", "/sandboxes/images");
const image = images.find((i) => i.os === "linux" && i.desktop && i.allowed && i.in_stock);
// 2. Start a sandbox from it.
let sandbox = await call("POST", "/sandboxes", { image_id: image.id });
try {
// 3. Wait until it runs.
while (sandbox.status !== "running") {
if (sandbox.status === "failed") throw new Error(sandbox.error);
await new Promise((resolve) => setTimeout(resolve, 2000));
sandbox = await call("GET", `/sandboxes/${sandbox.uuid}`);
}
// 4. Run a command on it.
const result = await call("POST", `/sandboxes/${sandbox.uuid}/exec`, { command: "uname -a" });
console.log(result.exit_code, result.stdout);
// 5. Look at its screen.
const shot = await call("POST", `/sandboxes/${sandbox.uuid}/computer`, { action: "screenshot" });
await writeFile("screen.jpg", Buffer.from(shot.image, "base64"));
} finally {
// 6. Destroy it, whatever happened: it is billed while it exists.
await call("DELETE", `/sandboxes/${sandbox.uuid}`);
} Use with AI agents
Building with a coding agent such as Claude Code, Cursor or Codex? Paste this prompt, finish its last line with what you want, and it has what it needs:
I want to use the Spaceyard API. It gives an AI agent a cloud computer (a Linux or Windows desktop) that it can run commands on and use like a person, with screenshots, clicks and typing.
Read the full reference first: https://spaceyard.dev/docs.md
The OpenAPI spec is at https://spaceyard.dev/openapi.json
Key facts:
- If you can run shell commands, the Spaceyard CLI is the shortest way: install it with `curl -fsSL https://spaceyard.dev/install.sh | sh` (on Windows, in PowerShell: `irm https://spaceyard.dev/install.ps1 | iex`), then run "spaceyard help". It reads the key from SPACEYARD_API_KEY. "spaceyard run <command>" runs one command in a fresh ephemeral sandbox and destroys it after; "spaceyard create" waits until the sandbox runs and prints its id; "spaceyard cp" copies files in and out; "spaceyard exec <id> <command>" exits with the command's exit code; "spaceyard fork <id>" snapshots and clones a sandbox; --json on any command gives JSON.
- Base URL https://api.spaceyard.dev/v1. JSON in and out.
- Authenticate every request with the header "Authorization: Bearer <key>". Read the key from the SPACEYARD_API_KEY environment variable; never put it in code.
- The flow: GET /sandboxes/images to pick an image, POST /sandboxes with {"image_id": ...}, then poll GET /sandboxes/{uuid} every 2 seconds until "status" is "running" (stop if it is "failed"). Then POST /sandboxes/{uuid}/exec with {"command": "..."} to run commands, and POST /sandboxes/{uuid}/computer with {"action": "screenshot"} (or click, type, key, scroll, open...) to use the desktop. DELETE /sandboxes/{uuid} when done.
- Errors are {"error": {"code": "...", "message": "..."}}. 409 means the sandbox is not running yet, 422 is a refusal or bad input (read the message), 429 means wait for the seconds in the Retry-After header.
- Sandboxes are billed by the minute while they exist, so always destroy them, also when something fails.
What I want to build: These docs are also in plain text, for agents and tools to read:
- https://spaceyard.dev/docs.md: this page as Markdown.
- https://spaceyard.dev/llms.txt: an index of Spaceyard for language models.
- https://spaceyard.dev/llms-full.txt: everything in one file.
- https://spaceyard.dev/openapi.json: the API as an OpenAPI 3.1 spec, for code generators and tool calling.
Authentication
Every request carries your API key as a bearer token:
Authorization: Bearer <your API key> An account has one key. Making a new one on the API key page replaces the old one, which stops working at once, and the key is shown only when it is made. It can do everything your account can, so keep it on your server: never in a browser or an app you hand out.
A request without a key, or with one that is not valid, gets 401 with the code UNAUTHENTICATED or INVALID_TOKEN. A suspended account gets 403 with ACCOUNT_BANNED.
Errors
Success is a 2xx status. Anything else carries an error object with a code you can branch on and a message you can show. A validation error lists what is wrong with each field in details.
{
"error": {
"code": "VALIDATION_ERROR",
"message": "The image id field is required.",
"details": {
"image_id": [
"The image id field is required."
]
}
}
} {
"error": {
"code": "UNPROCESSABLE",
"message": "As a first time user, we require you to top up a total of 10€ to start sandboxes."
}
} | Status | Code | Means |
|---|---|---|
| 401 | UNAUTHENTICATED, INVALID_TOKEN | No key, or not a valid one. |
| 403 | ACCOUNT_BANNED | The account is suspended. |
| 404 | NOT_FOUND | No such sandbox on your account, or no such endpoint. |
| 409 | CONFLICT | The sandbox is not running: start it first. |
| 422 | VALIDATION_ERROR | A parameter is missing or wrong; see details. |
| 422 | UNPROCESSABLE | Valid, but refused: not enough credit, over your account's limits, or out of stock. The message says which. |
| 429 | RATE_LIMITED | Too many requests; wait for Retry-After seconds. |
| 503 | UNAVAILABLE | The sandbox did not answer, usually because it has only just started. Try again in a few seconds. |
| 500 | INTERNAL_ERROR | Something went wrong on our side. |
Rate limits
Requests are counted per minute. Computer use and commands come in bursts, so they have limits of their own:
| Requests | Per minute |
|---|---|
| Computer use | 600 |
| Run a command | 120 |
| Create, start and stop | 30, and they count toward the 60 below too |
| Everything else | 60 |
Over a limit, a request gets 429. Its Retry-After header says how many seconds to wait, and X-RateLimit-Limit and X-RateLimit-Remaining say where you stand.
Lifecycle
A sandbox's status is one of these:
creating | Being made. Ask again in a few seconds. |
starting | Booting after a start. |
running | Up: commands and computer use work. |
stopping, stopped | Shut down. Its disk is kept, and start brings it back as it was. |
deleting, deleted | Destroyed, disk and all. |
failed | Could not start; error says why. Destroyed after an hour. |
A sandbox looks after itself. With auto_stop_minutes it stops after that long without commands or computer use (0 never stops it; otherwise 5 to 43,200). With auto_destroy_minutes it is destroyed after being stopped that long: -1 keeps it, and 0 makes it ephemeral, destroyed as soon as it stops. The defaults are in List images, under lifecycle.
Some sandboxes are handed over already running, from a pool kept warm for each image: then from_pool is true and the status is running straight away.
How many sandboxes you can run at once, and how large, depends on your account's level, which rises with the credit you have added. List images shows your limits and marks the images you may start.
Environment variables
Give a sandbox secrets and settings when you create it, as env: an object of names and values. They are set for every command you run on it.
{
"image_id": 1,
"env": {
"OPENAI_API_KEY": "sk-...",
"TARGET_URL": "https://example.com"
}
} - Up to 50 variables, 32 KB in all.
- Names are letters, digits and underscores, not starting with a digit.
- Values are text or numbers.
- They are stored encrypted. The API only ever shows their names, never the values.
- They are set when the sandbox is created and cannot be changed afterwards.
Billing
Sandboxes are paid from your credit, by the minute. A running sandbox pays its hourly_price: its vCPUs, memory and disk. A stopped one pays only for its disk, the stopped_hourly_price. Prices are in euros, and both are on every image and sandbox.
- A new account adds at least €10 before its first sandbox.
- Creating or starting a sandbox needs credit for an hour of it, at least €0.10.
- When your credit runs out, running sandboxes stop, and ephemeral ones are destroyed.
- Stopped sandboxes keep paying for their disk, and are destroyed after 72 hours without credit.
Add credit, or turn on auto-recharge, on the console's Billing page.
Live desktop
To watch what an agent is doing, or to take over, open the sandbox in the console: its Desktop tab shows the screen live, and you can use it with your own mouse and keyboard while the agent works through the API.
To embed a live screen in your own app or connect a VNC client directly, call Stream the screen for a tokenized embed_url (ready for an <iframe>) and a one-time VNC WebSocket URL.