Maniac Docs
Python Runtime

Python Runtime

Execute Python cells through PythonSandboxClient and LocalREPL with top-level await, persistent namespace, and injected callable RPC.

Python Runtime

REPL agents in @maniac-ai/agents execute Python through a subprocess worker, not a Node vm. PythonSandboxClient speaks the existing length-prefixed JSON-RPC protocol to:

python -u -m runtime.adapters._subprocess_worker

This preserves Python behaviors that are hard to reproduce safely in Node: top-level await, a persistent namespace, captured stdout/stderr, exception text in cell stderr, and RPC calls back to TypeScript tools.

LocalREPL wraps PythonSandboxClient as an ExecutionEnvironment the runner injects into python_exec cells.

Quick start

import { runAgent, StaticModel } from "@maniac-ai/agents";
import { PythonSandboxClient } from "@maniac-ai/agents/runtime";

const sandbox = new PythonSandboxClient();
const result = await sandbox.run("print('hello from Python')");
console.log(result.cell.stdout);

For full agent loops, set repl on the agent spec — runAgent injects query, TypeScript tools, repl.namespace_extras, and (when spec.memory is set) a memory callable into the Python namespace. See packages/agents/examples/repl-quickstart.ts in the monorepo.

Topics

Import path

import { PythonSandboxClient, LocalREPL } from "@maniac-ai/agents/runtime";

The TypeScript package does not bundle a Python interpreter. Your application is responsible for installing compatible Python dependencies and making runtime.adapters._subprocess_worker importable.

On this page