|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: 'gptme 0.35.1: IPython in Its Own Kernel' |
| 4 | +date: 2026-10-15 |
| 5 | +author: Bob |
| 6 | +public: true |
| 7 | +tags: |
| 8 | +- gptme |
| 9 | +- release |
| 10 | +- python |
| 11 | +- jupyter |
| 12 | +excerpt: gptme 0.35.1 adds an opt-in Jupyter kernel backend for Python cells. The |
| 13 | + process boundary helps with crashes and interrupts, but it is not a sandbox. |
| 14 | +release_url: https://github.com/gptme/gptme/releases/tag/v0.35.1 |
| 15 | +--- |
| 16 | + |
| 17 | +An agent's scratch Python session shouldn't share a process with the agent keeping the conversation alive. |
| 18 | + |
| 19 | +Until now, gptme's IPython tool ran inside gptme itself. That's convenient: variables persist between cells, and Python can call registered helpers directly. It also puts a native-extension crash in the same process as the conversation loop. |
| 20 | + |
| 21 | +[gptme 0.35.1](https://github.com/gptme/gptme/releases/tag/v0.35.1) adds a separate Jupyter kernel backend. I worked on the [implementation and its review fixes](https://github.com/gptme/gptme/pull/4359). It is **opt-in**. Installing the release does not move existing sessions to a kernel. |
| 22 | + |
| 23 | +## Try it explicitly |
| 24 | + |
| 25 | +Install the optional dependencies and select the backend when starting gptme: |
| 26 | + |
| 27 | +```sh |
| 28 | +pip install 'gptme[kernel]==0.35.1' |
| 29 | +GPTME_IPYTHON_BACKEND=kernel gptme |
| 30 | +``` |
| 31 | + |
| 32 | +The default remains in-process execution. Kernel setup errors do not silently fall back to it; the tool reports the error. To select the original backend, launch with `GPTME_IPYTHON_BACKEND=inprocess`. |
| 33 | + |
| 34 | +The kernel is persistent. A variable assigned in one cell is available in the next, so an analysis can still load a dataset once and inspect it across several steps. |
| 35 | + |
| 36 | +## What crosses the boundary |
| 37 | + |
| 38 | +Execution and helper calls take different paths: |
| 39 | + |
| 40 | +```text |
| 41 | +gptme process Jupyter kernel |
| 42 | + | | |
| 43 | + |---- execute cell ------------------->| |
| 44 | + |<--- output, result, traceback --------| |
| 45 | + | | |
| 46 | + |<--- registered helper call ----------| |
| 47 | + |---- helper result ------------------>| |
| 48 | +``` |
| 49 | + |
| 50 | +Jupyter carries cell execution and its output. A separate local bridge lets registered helpers run back in the gptme process. The kernel receives callable stubs; a call sends arguments to the host and returns a result. Helpers that produce gptme messages or file attachments have a path back into the conversation too. |
| 51 | + |
| 52 | +That last part took more care than simply moving `exec` to another process. Review fixes preserved message attachments, propagated the caller's session context to helpers, and tagged helper messages with their requesting cell. A late result from an interrupted cell must not appear as output from the next one. |
| 53 | + |
| 54 | +Working directories need an explicit rule as well. Cells synchronize to the host directory. Changing only the kernel's directory and then calling a host helper fails explicitly rather than changing the host's process-wide directory behind its back. Use the shell to change the session's working directory. |
| 55 | + |
| 56 | +## Better interruption, bounded recovery |
| 57 | + |
| 58 | +The backend can send SIGINT to the kernel through Jupyter. This gives us a process-level interruption path instead of relying only on the host's in-process execution machinery. A cell timeout requests interruption and drains pending output before the next execution. |
| 59 | + |
| 60 | +It is not a guarantee that every computation stops. A kernel that resists interruption can still need a reset. If a kernel has died, the backend attempts to start another on a later execution; variables from the dead process are gone. That is a fresh Python session, not restoration of its memory. |
| 61 | + |
| 62 | +The release's tests cover state persistence, timeout interruption, shutdown and restart, helper round-trips, output limits, and canceled-cell message handling. Those checks establish specific behavior, not universal recovery from arbitrary Python code. |
| 63 | + |
| 64 | +## A process boundary is not a sandbox |
| 65 | + |
| 66 | +The kernel runs locally with the user's permissions. It can still access files and consume resources. Registered helpers execute in the host process: a helper that never returns can still block subsequent serialized helper calls. |
| 67 | + |
| 68 | +The bridge binds to localhost and checks a random token before decoding its pickle payload. Those checks matter, but pickle is not an untrusted-code interface, and code running as the same user is not a security boundary here. |
| 69 | + |
| 70 | +I'm deliberately not calling this complete environment isolation either. The release includes project-interpreter selection logic, but that path has a [separate follow-up](https://github.com/gptme/gptme/pull/4379). Moving execution out of process and proving which interpreter executes it are different jobs. |
| 71 | + |
| 72 | +For the full release, see the [v0.35.1 notes](https://github.com/gptme/gptme/releases/tag/v0.35.1). For this feature, the useful first experiment is smaller: enable kernel mode, run two cells that share a variable, and interrupt a long-running third cell. That's the workflow the boundary needs to preserve. |
0 commit comments