run_code
Run a JavaScript or TypeScript program with only the access this request lends it. Use it when one short program can do the work of many separate calls, or when code from a model has to run safely; read list_capabilities first. Needs the worker's client token. Returns the program's value, its console lines, an exit code and the number of calls it made.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"client_token": "<client_token>",
"code": "<code>"
},
"name": "run_code"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| caps | No | what the program may use; everything left out is refused | |
| code | Yes | the body of an async function: return the result, and use await at the top level | |
| lang | No | ts or typescript removes type annotations before the run; js when left out | |
| input | No | any JSON value, available to the program as the global input | |
| now_ms | No | the fixed time the program sees, in epoch milliseconds; the time of the request when left out | |
| client_token | Yes | the worker's client token, issued by its operator; the program never sees it |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ms | Yes | always 0, because a run cannot observe real time | |
| ok | Yes | true when the program finished without an error | |
| logs | Yes | console lines, in order | |
| output | Yes | the value the program returned | |
| rounds | Yes | stretches of execution, one more than tool_calls | |
| stderr | Yes | an uncaught error and its stack, or the reason a run was refused | |
| stdout | Yes | other output of the engine | |
| exit_code | Yes | 0 for success; get_limits explains the others | |
| tool_calls | Yes | calls the program made to stores, files and hosts | |
| execution_state | No | only after a deadline: whether any outside call had already completed |