run_code
Runs Python in the sandbox. Risky code waits for button approval.
The code is scanned first. Safe code runs. Medium and high risk code returns an approval request and waits for a button. Secret placeholders are filled in only after the scan. Output is redacted.
- Tool name
- run_code
- Group
- Terminal and Python sandbox
- Risk
- high
- Needs approval
- sometimes
- Approval rule
- FREE or LOW code runs. MEDIUM and HIGH wait for a button unless the chat has Allow Session (MEDIUM only) or an /allow window.
- Allowed in scheduled jobs
- No
- Default
- on
Parameters
| Name | Type | Required | Default | Meaning | Limits |
|---|---|---|---|---|---|
| code | string | Yes | Python source to run. | Wall-clock limit 60 seconds by default; memory limit 512 MB by default. | |
| terminal_id | string | No | Id of a terminal session. Omit to use the first one. |
Returns
JSON with terminal id, output and exit status.
Example (made up for this page)
{
"code": "demo"
}{"terminal_id": "t1", "stdout": "42\n", "returncode": 0}Side effects
- Runs code as the bot's OS user inside a limited subprocess
- Can write files in a temp folder and use the network.
How it can fail
| When | What the agent sees |
|---|---|
| The code is risky | Command Approval Required with an id, level and reason |
| The code times out | A timeout result |
| The terminal is dead | Terminal not found or dead. |
See also:Terminal and Python sandbox tools
Checked against the source at commit f4fd89f on 29 Oct 2026. Everything here is merged on the main branch; no release has been tagged yet. The source is private, so these pages are the public description.