Skip to main content

Code execution

The Code execution toolkit lets hosted agents run Python in an isolated sandbox: analyse data, do exact calculations, convert files, and make documents, spreadsheets and charts that a model cannot write as text.

Example. At Acme Inc, Lee asks his co-worker "compare Q3 spend by vendor against budget and give me an Excel file with a chart". The co-worker passes the two exported spreadsheets from Lee's files into run_code, which builds the comparison with formulas and a chart. The workbook is saved to Lee's files, and the co-worker shares the file in the chat.

Tools​

ToolTitleWhat it doesKindBy default
run_codeRun codeRuns Python in a fresh sandbox, with input files placed in it first. Returns the exit code, the output and errors, and every file the code wrote, saved to the agent's files.Write, inside CortexHub: it saves files to the agent's files; nothing outside the sandbox changesRuns

The agent finds run_code with cortexhub_search_tools and runs it with cortexhub_invoke_tools, where it is named code-execution.run_code.

Who can use it​

Co-workers and hosted organisation agents. Apps a member connects, such as Claude and ChatGPT, and your own agents through the SDK run code in their own environment, so the tool is not offered to them. Code execution is in every organisation's toolkits, and every member and agent group gets it unless an admin unpublishes it there; there is nothing to connect.

How it works​

  • Isolated. Each call starts a new sandbox and stops it afterwards; nothing carries over between calls. The sandbox has no network access and no cloud or toolkit credentials, so code cannot reach your systems or the internet.
  • Files in. The agent passes files from its files by handle (cxh-file:// and the file id). The exact original file is placed in the sandbox, not its extracted text. The agent cannot pass a file it cannot open.
  • Files out. Every file the code writes under output/ is saved to the agent's files and returned as a handle the agent can pass to another tool, such as an email attachment. Writing a file with the same name as an input file saves it as a new version of that file; the earlier version is kept.
  • Python only, with common document, data and charting libraries installed (pandas, openpyxl, python-docx, python-pptx, reportlab, pdfplumber and matplotlib among them).
LimitValue
Time per call5 minutes
Input files per call20
Output files per call20, each up to 10 MB, 25 MB in total
Code per call200,000 characters

A file that goes over a limit is reported by name and size rather than dropped silently. A run that takes too long stops and says so.

Control it​

WhoWhereWhat
AdminGroups & access -> a group -> Toolkits & Tool Access -> Code execution -> PoliciesTurn Code execution off for the group's agents.
AdminToolkitsRemove Code execution from the organisation.
AdminA group's toolkit Policies tabHold run_code (for example, ask the member first) with a tool override on the group's toolkit Policies tab (Override decision on the tool).

Because run_code changes nothing outside the sandbox, nothing holds it by default. Anything the agent then does with the result, such as emailing the workbook, is a separate call that your policies decide.

See also​