interpreter

Run a cell of Python, JavaScript, TypeScript, R, Java, Bash or Go in a stateful context and return its results.

Variables, imports and functions persist between calls to the same context, like a notebook (Go keeps declarations, not values: each Go cell is compiled with the functions, types and imports of earlier cells and run). Returns stdout, stderr, results (a MIME bundle each: text/plain, text/html, image/png as base64, image/svg+xml, text/markdown, application/json, application/vnd.runtime.table+json for a table), and an error with its traceback. matplotlib figures and R plots are returned as PNG images; a pandas DataFrame, an R data frame and a JavaScript array of objects as tables. In every language, display returns a file (.png .jpg .svg .html .md .json .txt, .csv as a table) as a result. A value larger than 48 KiB, and output beyond 256 KiB per stream, is written to a file in the sandbox and returned as a ref you can fetch with the result route. Needs the exec, write_file and read_file scopes. python3, node and bash are in the default image. R (r-base-core), Java (openjdk-21-jdk-headless) and Go (golang-go) are installed from the Ubuntu archive on a context's first start when the image lacks them, which takes tens of seconds once and needs the archive allowed by the sandbox's network rules.

post/v1/sandboxes/{id}/interpreter:run

Request

  • Base URL: https://api.withruntime.com
  • URL: https://api.withruntime.com/v1/sandboxes/{id}/interpreter:run
  • Auth: HTTP bearer

Path parameters

idstring required

Resource identifier (UUID).

Headers

Idempotency-Keystring

Replaying the same key with the same request within 24 hours returns the first result and never repeats the effect. A refusal is not kept: a request refused before it ran (no_capacity, busy, a limit) runs afresh when sent again with its key. The SDKs send one automatically; the server makes one when absent and returns it in the idempotency-key response header.

Request body

codestring required

The cell to run.

language'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | 'go'

python by default. R, Java and Go are installed on first use (tens of seconds, once) when the image lacks them.

contextstring

A context's id; each language's name is its default context, started on first use.

timeoutMsinteger

Interrupt the cell after this long; 0 disables the cell deadline. The sandbox lease still applies. The context survives an interrupt; a cell that ignores it is killed 5 s later with its context.

streamboolean

Stream events as newline-delimited JSON (application/x-ndjson) while the cell runs, ending with the execution.

interruptOnDisconnectboolean

Interrupt the cell when the caller disconnects. false detaches the reader and leaves the cell running under the sandbox's lease.

Response

Success

idstring required
contextIdstring required
language'python' | 'javascript' | 'typescript' | 'r' | 'java' | 'bash' | 'go' required
executionCountinteger nullable
status'ok' | 'error' | 'interrupted' | 'timeout' | 'lost' required
stdoutstring required
stderrstring required
durationMsinteger

Changes

No recorded changes to this operation across all 1 revision of this API.