Resources·Docs

RareCloud AI Sandboxes: run untrusted code from your agent

Reference for RareCloud AI Sandboxes (beta): create an isolated sandbox, run Python, Node or shell commands, read and write files, with every CLI command, the Terraform resource and the API calls.

By RareCloud Team · 11 min read · 7 Oct 2026 · Updated 17 Oct 2026

In one paragraph: an AI sandbox is a small, isolated Linux environment that you create with one API call, use to run code an AI model wrote (or anything else you do not want on your own machines), and throw away when you are done. Each sandbox runs in its own hardened container in our European cloud region (Bucharest), cannot see other customers or our internal networks, and can reach the public internet so pip install and npm install work. You drive it through the public API at https://api.rarecloud.io/v1, the CLI (version 0.4.0) or the Terraform provider (version 0.4.0). AI Sandboxes are in beta; the section What is not ready yet lists exactly what still behaves differently from the final product.

Before you start

  • A RareCloud account and an API token. Create the token in the console under Account, then API tokens with services:read (list, get, read files) and services:write (create, run, write files, delete). Scopes match exactly, so :write does not include :read.
  • The CLI, the Terraform provider, or any HTTP client. The examples use the CLI and curl:
export RARECLOUD_TOKEN=rc_pat_...

Templates

A template decides what is installed and how big the sandbox is.

TemplateWhat is insideBilled size
python (default)Python 3.12 with numpy, pandas, matplotlib, scipy, scikit-learn, requests, pillow and openpyxl1 vCPU, 2 GB RAM
nodeNode.js 221 vCPU, 2 GB RAM
baseA minimal Debian 12 shell (bash, curl, git, jq, unzip)1 vCPU, 1 GB RAM

Every template runs as an unprivileged user (uid 10001) in /home/user. The system files are read only; /home/user (2 GB) and /tmp (1 GB) are writable and last as long as the sandbox does. Through the API you can also start from your own public container image by passing image (for example "image": "nginx:1.27"); the template you pick still sets the size. Private images are not supported yet. In 0.4.0 the CLI takes a custom image with rarecloud sandbox create --image <ref>, and the Terraform provider with the image argument of rarecloud_sandbox (changing it replaces the sandbox).

Step by step

1. Create a sandbox

rarecloud sandbox create --template python
curl -s https://api.rarecloud.io/v1/sandboxes \
  -H "Authorization: Bearer $RARECLOUD_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"template": "python"}' | jq .data

The response carries the sandbox id (it starts with sbx-), its status (pending, running or terminated), the template, createdAt and timeoutMs. A new sandbox is pending for a few seconds while it starts; a call made too early answers that the sandbox is not ready yet, so retry shortly.

2. Run code

rarecloud sandbox run <id> --code 'import pandas as pd; print(pd.__version__)'
rarecloud sandbox run <id> --file analysis.py
echo 'console.log(6 * 7)' | rarecloud sandbox run <id> --language node
curl -s https://api.rarecloud.io/v1/sandboxes/<id>/run_code \
  -H "Authorization: Bearer $RARECLOUD_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"language": "python", "code": "print(2 + 2)"}' | jq .data

You get back stdout, stderr and exitCode. The CLI prints the two streams to your own stdout and stderr and exits with an error when the remote exit code is not zero, so it works in scripts. language is python or node; use the template that has that runtime (the base template has neither).

Each call is a fresh process. Variables and imports do not carry over from one run to the next. Keep state in files (step 4) or send the whole script in one call.

3. Run shell commands

rarecloud sandbox exec <id> -- pip install duckdb
rarecloud sandbox exec <id> -- ls -la /home/user
curl -s https://api.rarecloud.io/v1/sandboxes/<id>/commands \
  -H "Authorization: Bearer $RARECLOUD_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"cmd": "python -c \"import sys; print(sys.version)\""}' | jq .data

The command runs with sh -c, so pipes and && work. The CLI joins everything after -- into one command line; quote anything your local shell would otherwise expand.

4. Read and write files

From the CLI 0.4.0 use rarecloud sandbox files get <id> <path> and rarecloud sandbox files put <id> <path>, or the API calls below. Paths must be absolute, and parent directories are created for you.

# Write a file
curl -s -X PUT https://api.rarecloud.io/v1/sandboxes/<id>/files \
  -H "Authorization: Bearer $RARECLOUD_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"path": "/home/user/data.csv", "content": "a,b\n1,2\n3,4\n"}'

# Read it back
curl -s "https://api.rarecloud.io/v1/sandboxes/<id>/files?path=/home/user/data.csv" \
  -H "Authorization: Bearer $RARECLOUD_TOKEN" | jq -r .data.content

File content travels as a text string (up to 1,000,000 characters per write). For binary data, encode it (for example base64) and decode it inside the sandbox with a command.

5. List and delete

rarecloud sandbox list
rarecloud sandbox get <id>
rarecloud sandbox rm <id>
curl -s -X DELETE https://api.rarecloud.io/v1/sandboxes/<id> \
  -H "Authorization: Bearer $RARECLOUD_TOKEN"

Delete every sandbox when you are done with it. A sandbox is stopped and deleted when its lifetime (timeoutMs, shown as expiresAt) runs out, and billing stops then at the latest, but deleting it earlier stops the charge sooner.

Every CLI command

From the 0.4.0 release binary. rarecloud sbx and rarecloud sandboxes are aliases for rarecloud sandbox, and every command accepts the global flags (-o json, --token, --api). sandbox create --run (or --entrypoint, or a command after --) starts the image's own program instead of waiting for commands; the sandbox ends when it exits, and sandbox logs shows its output.

CommandWhat it does
rarecloud sandbox create [-- command args...]Create a sandbox (defaults to the python template). Flags: --entrypoint, --image, --run, --template, --timeout
rarecloud sandbox exec <id> -- <cmd...>Run a shell command inside a sandbox
rarecloud sandbox expose <id> <port>Not available yet: preview URLs for a sandbox port
rarecloud sandbox files get <sandbox-id> <path>Download a file from a sandbox (to stdout, or to --output with mode 0600). Flags: --force, --output
rarecloud sandbox files put <sandbox-id> <path>Upload a file to a sandbox (from --from, or stdin); at most 25 MiB. Flags: --from
rarecloud sandbox get <id>Show one sandbox
rarecloud sandbox listList your sandboxes
rarecloud sandbox logs <sandbox-id>Print the last lines of a sandbox's output (live, or kept for 24 h after a run-mode exit). Flags: --tail
rarecloud sandbox rm <id>Terminate and delete a sandbox
rarecloud sandbox run <id>Run code inside a sandbox (--code, --file, or stdin). Flags: --code, --file, --language
rarecloud sandbox templatesList sandbox templates with size and hourly price

Terraform

The rarecloudio/rarecloud provider 0.4.0 has one sandbox resource. Terraform creates and deletes sandboxes; running code in them is done with the CLI or the API.

rarecloud_sandbox

ArgumentRequiredNotes
templatenopython (default), node or base. Changing it replaces the sandbox.
imagenoA custom public image instead of the template's image, for example nginx:1.27 (Docker Hub, ghcr.io, quay.io, registry.k8s.io, public.ecr.aws, gcr.io, mcr.microsoft.com). Changing it replaces the sandbox.
timeout_msnoLifetime in milliseconds, up to 3,600,000 (default 300,000; the API raises anything under 60,000 to 60,000). Changing it replaces the sandbox.
runnoRun mode: run = {} runs the image's own program, entrypoint and command (lists) replace the image's ENTRYPOINT and CMD; with a template command is required. The sandbox ends when the program exits. Changing it replaces the sandbox.

Exports id, status (pending, running, terminated, or exited in run mode), created_at, expires_at (when the sandbox stops and is deleted) and exit_code (run mode, once the program has exited). A sandbox that no longer exists drops out of state and is created again on the next apply; an exited run-mode sandbox disappears 24 hours after it ended.

resource "rarecloud_sandbox" "ci" {
  template   = "python"
  timeout_ms = 300000 # 5 minutes
}

output "sandbox_id" {
  value = rarecloud_sandbox.ci.id
}
rarecloud sandbox run "$(terraform output -raw sandbox_id)" --code 'print("hello")'

MCP tools

The MCP server (@rarecloudio/mcp-server 0.4.0) has ten sandbox tools: list_sandboxes, get_sandbox, list_sandbox_templates, read_sandbox_file, get_sandbox_logs, create_sandbox, delete_sandbox, run_sandbox_code, run_sandbox_command and write_sandbox_file. They answer 503 until AI Sandboxes launch in production.

API reference

All routes are under https://api.rarecloud.io/v1 with Authorization: Bearer <token>. Responses use the { "ok": true, "data": ... } envelope; errors are { "ok": false, "error": { "code", "message" } }.

Method and pathScopeBody or queryReturns
GET /sandboxesservices:read{ sandboxes: [...] }
POST /sandboxesservices:write{ template?, image?, timeoutMs? }The sandbox
GET /sandboxes/{id}services:readThe sandbox
DELETE /sandboxes/{id}services:write{ ok: true }
POST /sandboxes/{id}/run_codeservices:write{ language: "python" | "node", code } (code up to 100,000 characters){ stdout, stderr, exitCode }
POST /sandboxes/{id}/commandsservices:write{ cmd } (up to 10,000 characters){ stdout, stderr, exitCode }
GET /sandboxes/{id}/filesservices:read?path=/absolute/path{ path, content }
PUT /sandboxes/{id}/filesservices:write{ path, content }{ ok: true }
POST /sandboxes/{id}/ports/{port}services:write{ url } (not routed yet)

A sandbox id that belongs to another account answers 404, exactly like one that does not exist.

Isolation and network

  • Each account gets its own isolated space; sandboxes of different customers never share it.
  • Nothing can connect into a sandbox from outside.
  • A sandbox can connect out to the public internet on any port (package indexes, git, your own APIs). Private address ranges, link-local addresses (including cloud metadata services) and our internal networks are blocked.
  • A sandbox never holds credentials for the platform it runs on.

Limits

LimitValue
Resources per sandboxUp to 1 vCPU and 2 GB RAM, whatever the template
Sandboxes running at once8 per account (each counts 1 vCPU and 2 GB against an account total of 8 vCPU and 16 GB)
Writable disk2 GB in /home/user, 1 GB in /tmp, per sandbox
timeoutMs1,000 to 3,600,000 (default 300,000, five minutes)
Code per run_code call100,000 characters
Command per commands call10,000 characters
File content per write1,000,000 characters

What is not ready yet

AI Sandboxes are a beta. These are the gaps today, all checked against the current code:

  • Preview URLs are not available. POST /sandboxes/{id}/ports/{port} answers 501 and sandbox expose says so: a sandbox accepts no inbound connections. Read results with run, exec, logs or the files commands.
  • The prices below are provisional. Runtime is metered per second, from the moment the sandbox runs until you delete it or it expires, onto the monthly cloud invoice.
  • Rich results are not returned. run_code gives you stdout, stderr and the exit code; charts and dataframes are not sent back as objects. Save a chart to a file and read the file instead.
  • Private custom images are not supported, only public ones.
  • Test mode: outside production the API can answer in a test mode where every response carries "mocked": true and code is not really executed. Treat any response with mocked as a test answer, never as a real result. Production never answers in test mode: without a sandbox cluster every sandbox call answers 503.

Pricing

Provisional beta prices. Billed per second from when the sandbox first runs until you delete it or it expires, on your cloud invoice.

TemplateSizePer hour
python1 vCPU, 2 GBEUR 0.064
node1 vCPU, 2 GBEUR 0.064
base1 vCPU, 1 GBEUR 0.052

That is EUR 0.04 per vCPU per hour plus EUR 0.012 per GB of RAM per hour. These numbers can change before general availability.

Troubleshooting

What you seeWhat it means
AI Sandboxes are not available yet. (HTTP 503)The product is not open yet.
Sandbox is not ready yet (no running pod). Retry shortly.The sandbox is still starting. Wait a few seconds and retry.
Sandbox not found. (HTTP 404)Wrong id, a deleted sandbox, or one that belongs to another account.
Unknown sandbox templateThe template must be python, node or base.
run_code fails with "not found" for python3 or nodeYou are on the base template, or used --language node on the python template. Use exec, or a template that has the runtime.
A variable from the previous run is undefinedEvery call is a new process. Put the whole script in one call or keep state in files.
File not found in sandbox.Check the path is absolute and the file exists (exec <id> -- ls -la <dir>).
Read-only file systemWrite under /home/user or /tmp.
exited with code N from the CLIYour code or command failed inside the sandbox; its stderr is printed above.
A permission errorThe token lacks services:read or services:write.

Related