Runtime

Run a code snippet

Writes code to a temp file and runs it with the chosen interpreter. Cleaner than /exec for multi-line scripts because you don't have to deal with shell escaping. Response shape matches /exec.

Supports the same stream: true opt-in as /exec; see that endpoint's description for the SSE event shape.

post/sandboxes/{id}/code

Path parameters

idstring required

24-char hex id of the sandbox.

Request body

language'python' | 'node' required
codestring required

Snippet source. Multi-line via \n in the JSON string.

timeout_secondsinteger
cwdstring
envobject

Extra environment variables for this snippet only. Same semantics as env on /exec, per-call override on top of the sandbox's default environment.

streamboolean

When true, the response is SSE (text/event-stream) as the snippet runs, same behaviour as /exec with stream: true.

Example request

{
  "env": {
    "OPENAI_API_KEY": "sk-..."
  }
}

Response

Code completed.

When the request body has stream: true, the response is text/event-stream, one ExecStreamFrame per data: event.

messagestring required

Example response

{
  "message": "Exec completed"
}

Changes

Changed in 2 of the 5 revisions of this API.12

  • 4a016f074bc011See the full diff
    • removed the media type application/x-ndjson for the response with the status 200

      response-media-type-removed

    • added the media type text/event-stream for the response with the status 200

      response-media-type-added

    • added the new optional request property env

      new-optional-request-property

    This revision also has 1 change that name no endpoint, such as unreferenced schemas being removed. See the revision's changelog