Python kernel
Give the agent a Python interpreter that stays running between calls, so loaded data, variables and imports are still there on the next step. Off by default.
Copy & share
On this page5 sections
The Python kernel gives the agent one Python interpreter that keeps running while you work in a project. Anything the agent loads or defines in one call is still there in the next call.
This is the difference from the shell tool. Every python -c in the shell starts a new process, so a script that loads a large file has to load it again for every question. With the kernel, the agent loads the data once and then asks as many questions as it needs:
python_kernel(code: "import pandas as pd; df = pd.read_csv('sales.csv'); df.shape")
→ (48211, 17)
python_kernel(code: "df.groupby('region').revenue.sum().sort_values().tail(3)")
→ region
EMEA 1840221.55
APAC 2110984.10
NA 3922015.77The second call did not read the file again. df was already in memory.
Turning it onLink to this section
The kernel is off by default. It runs any code the agent writes, with your user's permissions, which is as much power as the shell tool has. So you have to switch it on:
"agentFeatures": { "pythonKernel": true }You can also switch it on from the app:
- Terminal UI: run
/agent-featuresand turn on Python Kernel. - Desktop: open the Router panel, go to the Behavior section and turn on Python kernel.
- For one headless run:
EMPRYO_PYTHON_KERNEL=1 empryo --headless "…"
You need python3 (or python) on your PATH. If Empryo cannot find Python, the tool is not offered to the model at all.
ParametersLink to this section
| Field | Type | What it does |
|---|---|---|
code | string | The Python to run. Like a REPL, the value of the last expression is returned |
reset | boolean | Clear all variables first. Send it without code to just clear |
timeoutMs | number | Stop after this many milliseconds. Default 120000 (2 minutes), maximum 600000 (10 minutes) |
Each call returns what the code printed to stdout and stderr, plus the value of the last expression. If the code raises an exception, the call fails with the traceback, and the interpreter keeps running with its variables intact.
The Empryo API inside PythonLink to this section
Python code gets an api object with the same API code_script has: reading, search, the code index, the language server, edits, running commands and other tools. Calls are synchronous, keyword arguments become the options object, and a failed call raises ApiError.
python_kernel(code: "hits = api.grep('loadConfig', path='src'); len(hits)")
→ 14
python_kernel(code: "api.edit.file('src/config.ts', 'retries = 3', 'retries = 5')")
→ {'ok': True, 'report': 'Edited src/config.ts (lines 12-12)'}Edits made through api are checked, tracked and listed in the reply, and code_script(rollback:'<id>') undoes them. Waiting for an api call does not count toward the time limit.
When Stem is on, Python also gets a stem object: the same $ that Stem gives code_script, so its rules, notes and learning apply to Python's calls too. For one headless run, EMPRYO_STEM=1 or EMPRYO_STEM=0 turns Stem on or off.
Plain open() and subprocess still work, but they bypass api: those reads and writes are not checked or tracked.
Behaviour worth knowingLink to this section
- IPython is used when it is installed. You get rich output,
displayand_. Without IPython it uses plain Python. You do not need to install anything either way. - There is one kernel per tab. Each chat keeps its own variables, and its kernel stops when the tab closes.
- The working directory is the project root, so relative paths work as you expect.
- A code run that hits its time limit is stopped and the kernel restarts, so the turn does not hang. The reply tells the agent this happened. All variables are lost when that happens.
- It is not a Jupyter client. Empryo talks to the Python process directly, so you do not need Jupyter installed.
When not to use itLink to this section
Use shell for one-off commands such as pytest, ruff or a script you already have. The kernel adds nothing there, and it leaves a process running after the call.
Use the project tool for lint, typecheck and tests, because it already knows your toolchain.
The kernel is worth it when each step builds on data the previous step left in memory, such as exploring a dataset or debugging a calculation step by step.