For the complete documentation index, see llms.txt. This page is also available as Markdown.

Code execution

Execute Code

post

Run code in the gateway's sandbox and return its output.

The run is admitted as an otari_code_execution call is: a workspace whose code execution policy is off is refused, and its execution ceiling and pinned image apply. It is priced under otari:code_execution and reserved against the caller's budgets. file_ids puts uploads in the working directory, and each file the code writes comes back with a file_id. container: "auto" holds the sandbox after the run and names it in Otari-Container-Id; sending that id back runs in the same sandbox, with its files and interpreter state.

Authentication modes:

  • Master key: the user field is required and may name any existing user.

  • API key: usage and spend bind to the key's own user. A user field naming a different user is rejected with 403 (or ignored, when the key's own reject_user_mismatch is false, or the deployment-wide setting is disabled and the key does not override it); it is never billed to that user.

  • Service key: a user field names one of the key owner's end users, created on first use on the budget Otari-End-User-Budget names (or the key's default), and is billed and rate limited as that end user.

Authorizations
Otari-KeystringRequired

Enter your API key here (sent as Otari-Key header).

Body

A direct code execution request: the code to run, and the sandbox to run it in.

codestring · min: 1Required

Python source to run in the sandbox

containerstring · nullableOptional

'auto' to hold the sandbox after the run, or a container id an earlier response named in Otari-Container-Id to run in that sandbox again, with its files and interpreter state. Omitted, the sandbox is released when the run ends.

file_idsstring[] · max: 32 · nullableOptional

Uploads from POST /api/v1/files to put in the working directory before the code runs, each under its own filename.

timeout_secondsinteger · min: 1 · nullableOptional

How long the code may run. Never more than the workspace's code execution ceiling, or 60 seconds when it sets none.

userstring · nullableOptional

User ID for usage attribution

Responses
200

Successful Response

application/json

A completed code execution. Code that failed is a completed execution with a nonzero return_code.

objectconst: code_execution.resultOptionalDefault: code_execution.result
return_codeinteger · nullableRequired

The program's exit status; null when the sandbox did not report one.

stderrstringRequired
stdoutstringRequired
post/api/v1/code/execute
POST /api/v1/code/execute HTTP/1.1
Otari-Key: YOUR_API_KEY
Content-Type: application/json
Accept: */*
Content-Length: 42

{
  "code": "print(1 + 1)",
  "container": "auto"
}
{
  "files": [
    {
      "file_id": "text",
      "filename": "text"
    }
  ],
  "object": "code_execution.result",
  "return_code": 1,
  "stderr": "text",
  "stdout": "text"
}

Last updated

Was this helpful?