The run_code tool

run_code runs a small program in which DataMind Oda calls its other tools. This page covers the tool itself: what a call carries, how a run is bounded and approved, and how the result reads. How a run looks in a chat is on Programs Oda runs, and the form in which a chat is given this tool is on Tools and how they are offered.

What a call carries

ItemWhat it isRequired
codeThe program itself: the body of an async function. Top-level await and return both work, and the returned value comes back with the run.Yes
descriptionFive to ten words in active voice, saying what the program does; it appears as the title of the run in the chat.Yes
timeoutMsA longer time budget in milliseconds: a positive number, capped at the maximum. Omitted, the default applies.No
sandbox_permissionsA wider file-access mode for this complete program run.No
justificationA one-sentence reason why this run needs wider access; it is shown to you before the program starts.With sandbox_permissions

When the request is refused

RefusalWhat it means
invalid description: expected a non-empty stringThe description is missing or empty.
invalid timeoutMs: expected a positive finite numberThe time budget is not a positive number.
invalid escalation: sandbox_permissions requires a justificationA wider mode was asked for without a reason.
invalid escalation: justification is only valid together with sandbox_permissionsA reason was given without a wider mode.
invalid justification: expected a non-empty sentenceThe reason is empty.
timeoutMs is not available for this PTC runtime / sandbox_permissions is not available for this PTC runtimeThis setup's program runtime cannot honour that control, so the request is refused.

How a run works

Time and output limits

WhatThe limit
Default budget120,000 ms (about two minutes).
Ceiling600,000 ms (ten minutes); a longer request is capped, and a lower ceiling can apply in some setups.
The requestOnly a positive number of milliseconds; zero does not switch the deadline off.
What the budget coversThe whole run, including the time it spends waiting for the calls it makes and for your answers. It counts elapsed time, not processor time.
OutputThe printed lines and the returned value share a cap of 67,108,864 bytes (64 MiB). Past the cap, the fitting part of the output is kept.
MemoryThe program's own heap ceiling is 512 MiB; it is not a total memory cap for everything the run starts.

Wider access for one run

When the program tries to change files the chat's mode does not allow, the change is denied, and Oda can ask to run the same program once more with wider access.

How the result reads

A finished run returns the printed lines and the value the program returned, and two texts stand in for special outcomes:

The word in the parentheses names what ended the run:

KindWhat it means
exceptionThe program hit an error, or it could not be understood and did not run.
timeoutThe run reached its time budget.
abortThe run was stopped; a stopped run reports as an abort.
worker-exitThe run's process ended early, or its cleanup did not finish cleanly.
invalid-outputThe value the program returned cannot be carried as plain data.
output-limitThe run produced more output than the cap allows, so the fitting part is kept.
protocolThe run's own communication became malformed or too heavy, so the run was stopped.
sandbox-unavailableThe limits the run asked for could not be applied on this computer, so the run did not start rather than run without them.

Questions, answered

What does Oda send when it calls run_code?

The program and a short description of it. The program is the body of an async function, and the description says what it does in five to ten words. A call may also add a longer time budget and, for a run that needs it, a wider file-access mode with a one-sentence reason. A request that does not fit is refused before anything runs.

What is the run's short description for?

It says what the program does, in five to ten words in active voice, and it is what the run shows as its title in the chat. Every call carries one.

How is a run's time budget counted?

As elapsed time for the whole run, including the time it spends waiting for the calls it makes and for your answers. It is not a measure of processor time, so a run that mostly waits still reaches its deadline.

Can a run have no time limit?

Not a run started from a chat: run_code accepts only a positive number of milliseconds, the number is capped at the maximum, and zero does not switch the deadline off. Runs that other parts of Oda start, such as a workflow, can be requested without a deadline; the chat's tool cannot.

What does the justification do?

It is the one-sentence reason for asking wider file access. It is required together with a wider mode, and it is shown to you before the program starts. The widening covers that complete program run only.

Which console methods can a program print with?

Five: log, info, warn, error and debug. The lines are captured as the program prints them and come back with the run when it ends.

What happens to a call that is still waiting when the program ends?

It does not run. The run closes after the calls that had already started settle, and a call that never started is dropped. Nothing is retried on its own: before a new attempt, Oda checks what the earlier run already did.

What does a failed run keep from what it printed?

The fitting part of the lines printed before the failure, under Captured output:. The run also keeps the file-limit facts it ran under, including File sandbox enforcement is partial on this host. when the limits could only be applied partly on your computer.