Code Sandboxes
Execute Python or Node.js source in a short-lived isolated runtime, collect its output, and terminate it when finished.
Create templates and Code Sandboxes in the console or through the Control API. Both surfaces expose the same organization resources, status, limits, and lifecycle.
Code Sandboxes execute source code. They are not containers, remote development machines, job runners, or browser sessions. The API intentionally does not expose a shell, subprocesses, SSH, ports, Docker images, background services, git, or persistent volumes.
Template, sandbox, execution
Choose a prepared runtime, create a sandbox, then execute one source program at a time.
- 01Choose a template
Use a built-in runtime or a custom dependency template.
- 02Create a sandbox
Receive an isolated runtime with a fixed expiry.
- 03Run source code
Send code and stdin; receive stdout, stderr, and exit status.
Run Python in three stages
Use a Tarka API key and your organization ID. API keys are available in theTarka console.
Create a key with the sandboxes scope, then sendAuthorization: Bearer tk_live_... on every request. Keep API keys on your server; never ship them in browser code.
Create a sandbox
Built-in templates are ready to use without a custom dependency build.
POST /sandboxescurl -X POST "https://tarka.rest/control/v1/orgs/$TARKA_ORG_ID/sandboxes" \
-H "Authorization: Bearer $TARKA_API_KEY" \
-H "Idempotency-Key: create-demo-1" \
-H "Content-Type: application/json" \
-d '{
"template": "python-3.12",
"timeout_seconds": 300
}'application/json{
"id": "sbx_01K3H9Q2F7M6R5N4P3T2V1W0XY",
"status": "CODE_SANDBOX_STATUS_STARTING",
"template_alias": "python-3.12",
"runtime": "SANDBOX_RUNTIME_PYTHON",
"timeout_seconds": 300,
"expires_at": "2026-08-20T14:35:00Z"
}Creation is asynchronous. Poll the sandbox resource until its status isCODE_SANDBOX_STATUS_READY before executing code.
GET /sandboxes/{sandbox_id}curl \
"https://tarka.rest/control/v1/orgs/$TARKA_ORG_ID/sandboxes/$SANDBOX_ID" \
-H "Authorization: Bearer $TARKA_API_KEY"Execute source code
The template selects the runtime, so an execution only needs source code and its optional stdin. Save the sandbox id as SANDBOX_ID.
POST /sandboxes/:executecurl -X POST \
"https://tarka.rest/control/v1/orgs/$TARKA_ORG_ID/sandboxes/${SANDBOX_ID}:execute" \
-H "Authorization: Bearer $TARKA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "values = [21, 34, 55]\nprint(sum(values))",
"stdin": "",
"timeout_seconds": 10
}'application/json{
"id": "exec_01K3H9T4CX9J1W8M7N6P5Q4RST",
"status": "EXECUTION_STATUS_SUCCEEDED",
"stdout": "110\n",
"stderr": "",
"exit_code": 0,
"duration_ms": 47
}Terminate the sandbox
Sandboxes expire automatically. Terminate one as soon as you are finished to release its capacity immediately.
DELETE /sandboxes/{sandbox_id}curl -X DELETE \
"https://tarka.rest/control/v1/orgs/$TARKA_ORG_ID/sandboxes/$SANDBOX_ID" \
-H "Authorization: Bearer $TARKA_API_KEY"Versioned runtime environments
A template is a versioned runtime definition. Built-in templates contain the language runtime and its standard tooling.
| Alias | Runtime | Custom manifest |
|---|---|---|
python-3.12 | Python 3.12 | requirements.txt or pyproject.toml |
python-3.13 | Python 3.13 | requirements.txt or pyproject.toml |
node-22 | Node.js 22 | package.json |
node-24 | Node.js 24 | package.json |
Runtime versions are part of the template name. Use a complete alias such aspython-3.12 instead of relying on a moving python alias.
Preinstall project dependencies
Derive from a built-in template and attach exactly one dependency manifest. Tarka validates and prepares the dependencies before the template becomes available for sandbox creation.
requirements.txtUse pinned versions for repeatable builds.
pyproject.tomluv resolves dependencies; the project itself is not installed.
package.jsonDeclare runtime dependencies under dependencies.
POST /sandbox-templatescurl -X POST \
"https://tarka.rest/control/v1/orgs/$TARKA_ORG_ID/sandbox-templates" \
-H "Authorization: Bearer $TARKA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"alias": "python-data",
"display_name": "Python data",
"base_template_alias": "python-3.12",
"requirements_txt": "numpy==2.2.6\npandas==2.3.1\n",
"idempotency_key": "template-python-data-v1"
}'application/json{
"id": "stpl_01K3H8YD7G4M2P9R8S7T6V5WXY",
"alias": "python-data",
"base_template_alias": "python-3.12",
"status": "SANDBOX_TEMPLATE_STATUS_BUILDING",
"dependency_file_type": "requirements.txt",
"dependency_manifest_sha256": "d87d2b7...",
"created_at": "2026-08-20T14:25:00Z"
}Other supported manifests
pyproject.toml + uv{
"alias": "python-analytics",
"display_name": "Python analytics",
"base_template_alias": "python-3.12",
"pyproject_toml": "[project]\nname = \"analytics-runtime\"\nversion = \"0.1.0\"\ndependencies = [\"polars==1.32.0\"]\n"
}package.json{
"alias": "node-validation",
"display_name": "Node validation",
"base_template_alias": "node-22",
"package_json": "{\"private\":true,\"dependencies\":{\"zod\":\"3.25.76\"}}"
}Custom templates cannot run build scripts supplied by the caller, install operating system packages, copy arbitrary files, set a startup command, or keep a process warm. Only dependency manifests are accepted. URL, git, local-path, editable, custom-index, workspace, and lifecycle-script dependency sources are rejected. Python packages must have wheels and Node installation always uses --ignore-scripts.
Build states
A custom template moves through the BUILDING, READY, orFAILED enum states. Poll the template resource until it returnsSANDBOX_TEMPLATE_STATUS_READY before creating a sandbox from its ID or alias. Submitting the same request with its idempotency key returns the same template resource instead of creating a duplicate.
Source in, result out
Every call runs one source program with the sandbox's selected runtime. There is no command or executable field.
codestring · requiredPython or JavaScript source code to execute.
stdinstring · optionalText made available on standard input.
timeout_secondsinteger · optional1–30 seconds; defaults to 10.
Node.js example with JSON stdin
POST /sandboxes/:executecurl -X POST \
"https://tarka.rest/control/v1/orgs/$TARKA_ORG_ID/sandboxes/${SANDBOX_ID}:execute" \
-H "Authorization: Bearer $TARKA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"code": "const fs = require(\"node:fs\"); const input = JSON.parse(fs.readFileSync(0, \"utf8\")); console.log(input.values.reduce((a, b) => a + b, 0));",
"stdin": "{\"values\":[21,34,55]}",
"timeout_seconds": 10
}'Execution semantics
- Executions in one sandbox are serialized; only one is active at a time.
- Each execution starts a fresh language process. In-memory variables do not carry over.
- The temporary workspace lasts only for the sandbox and is discarded when it stops.
- Child processes and runtime package installation are blocked; add dependencies to a template.
- Output is captured separately as
stdoutandstderr. - A program error returns a completed execution with a non-zero
exit_code. - A timeout stops the execution without extending the sandbox expiry.
- Source and stdin are never stored. Encrypted output is retained for 15 minutes for idempotent reads.
Short-lived by design
A sandbox returns to ready after a successful or failed execution and may be used again until expires_at. Expiry and explicit deletion are terminal; create a new sandbox from the same template to continue.
Sandboxes use 1 vCPU and 1 GiB. Lifetime is 30–300 seconds and defaults to 300. The default organization quota is two active sandboxes, 20 creates/hour, 30 executions/hour, ten custom templates, and five builds/day.
Endpoint reference
All routes are scoped to an organization and use the Tarka control-plane base URL.
https://tarka.rest/control/v1Native gRPC is served at grpc.tarka.rest:443. The authoritative protobufs and OpenAPI contracts are public in the contract-onlyTarka API repository. Pin a tagged release and use Buf or protoc to generate a client for your language. The repository intentionally contains no generated SDK or service implementation. REST is generated from the same service annotations.
/orgs/{org_id}/sandbox-templatesList built-in and custom templates
/orgs/{org_id}/sandbox-templatesCreate a custom dependency template
/orgs/{org_id}/sandbox-templates/{template_id}Read template build status
/orgs/{org_id}/sandbox-templates/{template_id}Delete a custom template
/orgs/{org_id}/sandboxesList active and recent code sandboxes
/orgs/{org_id}/sandboxesCreate a code sandbox
/orgs/{org_id}/sandboxes/{sandbox_id}Read sandbox state
/orgs/{org_id}/sandboxes/{sandbox_id}:executeRun source code
/orgs/{org_id}/sandboxes/{sandbox_id}/executions/{execution_id}Read retained execution output
/orgs/{org_id}/sandboxes/{sandbox_id}Terminate a sandbox
Capacity and request rates
Approved organizations have no fixed count limit for active sandboxes, custom templates, or simultaneous template builds. Starts and builds need available shared capacity. Starting a sandbox also requires enough credit within your spending limits.
If all runtime capacity is in use, the API returns sandbox_cluster_capacity_unavailable with HTTP 429. Retry later or stop a sandbox you no longer need. Request-rate limits, execution timeouts, and runtime sizes still apply.
What belongs somewhere else
The narrow API keeps code execution predictable and easier to isolate.
Short Python or JavaScript programs with captured input and output.
Long-running commands, batch workloads, repository checkout, and generated artifacts.
Persistent processes, services, ports, state, tools, and private network access.
Shell commands and child processes, Dockerfiles and arbitrary images, OS packages, runtime dependency installation, background processes, HTTP servers, inbound ports, SSH, browser automation, git operations, file upload and download APIs, durable storage, and GPU execution.