Skip to Content
Tara Docs

Run code in a sandbox

Start a sandbox from code, run a script, read the result and stop it.

You need: an API key and added credit. Set TARA_BASE_URL (ending in /v1) and TARA_API_KEY as in First API call.

Start it for up to 10 minutes

curl -X POST "$TARA_BASE_URL/sandboxes" \
  -H "Authorization: Bearer $TARA_API_KEY" -H "Content-Type: application/json" \
  -d '{"timeout_seconds": 600}'

Note the id. Ten minutes of credit is held now.

Write a file

printf 'print(sum(range(1_000_001)))\n' | curl -X PUT "$TARA_BASE_URL/sandboxes/<id>/files?path=/tmp/sum.py" \
  -H "Authorization: Bearer $TARA_API_KEY" -H "Content-Type: application/octet-stream" --data-binary @-

Run it

curl -X POST "$TARA_BASE_URL/sandboxes/<id>/exec" \
  -H "Authorization: Bearer $TARA_API_KEY" -H "Content-Type: application/json" \
  -d '{"command": "python3 /tmp/sum.py"}'

The answer has stdout, stderr, exit_code, duration_ms, and truncated if the output was cut.

Stop it

curl -X DELETE "$TARA_BASE_URL/sandboxes/<id>" -H "Authorization: Bearer $TARA_API_KEY"

Only the seconds it ran are charged; the rest of the hold comes back.

Serving a preview

Start a server on a port inside the sandbox, then ask for its address:

curl "$TARA_BASE_URL/sandboxes/<id>/ports/8000" -H "Authorization: Bearer $TARA_API_KEY"

Anyone with that address can open it while the sandbox runs.