capsule.commands.run(), the interpreter keeps the kernel alive between calls — variables, imports, and function definitions all survive from one run_code() call to the next.
Quick start
Capsule class in wrenn.code_interpreter extends the standard capsule with run_code(). Pass wait=True to block until the capsule is running before you execute any code.
Stateful execution
The kernel persists between calls, so every assignment, import, and function definition you make in one call is available in the next.Reading output
run_code() returns an Execution object. Use result.text for the value of the last expression in a cell, and result.logs.stdout / result.logs.stderr for printed output.
result.text returns the text/plain representation of the main execute_result — the last expression in the cell. Calls to print() go to result.logs.stdout, not result.text.
Templates
The code interpreter uses thecode-runner-beta template by default. Pass a template= argument to use a custom Jupyter-enabled template instead.
Next steps
Execution
Learn about the
Execution object, error handling, and streaming callbacks.Rich output
Capture charts, images, HTML, and other rich MIME outputs from your code.