HeadlinesBriefing favicon HeadlinesBriefing.com

GitHub fugue-labs monty-go Pure Go WASM Python Interpreter

Hacker News •
×

GitHub repository fugue-labs/monty-go provides a pure-Go wrapper for Pydantic's Monty Python interpreter, compiled to WebAssembly and loaded via wazero. This enables running LLM-generated Python code safely from Go without containers, CGO, or subprocesses. The 2.9MB WASM binary embeds directly into Go binaries with sub-millisecond startup.

Instead of sequential tool calls requiring multiple model interactions, LLMs write Python code that calls Go functions directly. Monty pauses execution at each external function call, allowing Go code to handle it before resuming. This reduces three model calls to one, making LLM agents faster, cheaper, and more reliable.

The library supports resource limits including memory (10MB default), time (5 seconds), allocations (100,000), and recursion depth (100). Go's context.Context deadlines are respected for cancellation. Features include capturing Python print() output, handling OS filesystem and environment calls through Go callbacks, and registering multiple external functions with name-based dispatch.

Quick start demonstrates executing "x * 2 + y" with variables x=10, y=5 returning 25. External functions like get_weather, search, calculate, and store integrate seamlessly with Go implementations.