monty README

The project's README from github.com/pydantic/monty. As one markdown file: README.md.

Monty

A secure Python sandbox, written in Rust, for code written by AI.

CI Codspeed Coverage PyPI NPM crates.io license Join Slack

Monty avoids the latency, complexity and cost of a container based sandbox for running LLM generated code. It comes in two forms: OSS Monty, the MIT licensed Python 3.14 sandbox you install as a package, and Full Monty, the commercial server that runs the same sandbox behind a WebSocket as a service.

A new OSS Monty sandbox takes under 1ms from a running pool (Full Monty: about 2ms) compared to around 1500ms for a sandbox service.

Filesystem, environment variables and network do not exist inside the sandbox: it reaches the host only through the functions and mounts you pass in.

Documentation: pydantic.dev/docs/monty

Install

uv add pydantic-monty        # Python
npm install @pydantic/monty  # JavaScript / TypeScript
cargo add monty              # Rust

The commercial Full Monty runs the same workers as a container image.

Example

The code string is what a model writes when asked how long a bar of chocolate could power a lightbulb:

from pydantic_monty import Monty

code = """
kcal = nutrition('chocolate bar')['kcal']
hours = kcal * 4184 / (bulb_watts * 3600)
print(f'a chocolate bar powers a {bulb_watts} W bulb for {hours:.1f} hours')
"""

with Monty() as pool:
    with pool.checkout() as session:
        session.feed_run(
            code,
            inputs={'bulb_watts': 10},
            external_lookup={'nutrition': lambda food: {'kcal': 230}},
        )
        #> a chocolate bar powers a 10 W bulb for 26.7 hours

nutrition ran on the host and the sandbox saw only its return value.

Documentation

Monty runs Code Mode in Pydantic AI. Community bindings: gomonty (Go) and dart_monty (Dart / Flutter).

Part of the Pydantic Stack

The Pydantic Stack is everything you need to ship production-grade AI agents:

monty (pydantic/monty)

Searching Database…

8.7K ·GitHub
What is this?Monty is a minimal, secure Python interpreter written in Rust, built so AI models can run generated Python code without the latency and overhead of a container sandbox.
Is this a library I install, or a hosted service?It comes in two forms: OSS Monty, an MIT-licensed Python package you install directly, and Full Monty, a commercial server that runs the same sandbox behind a WebSocket as a service.
How do I get started with it?Install OSS Monty as a Python package and follow the docs' getting-started guide for Python, JavaScript, or Rust; the commercial Full Monty deploys as a container image of the same workers.
Do I need Python 3.14, or can I call it from other languages too?OSS Monty targets Python 3.14, but there are community bindings for Go (gomonty) and Dart/Flutter (dartmonty), plus native getting-started guides for JavaScript and Rust.
What can't the sandboxed code do?Inside the sandbox there is no filesystem, no environment variables, and no network — code can only touch the host through the functions and mounts you explicitly pass in, and it runs only a supported Python subset.
Is Monty fully open source, or do I need a paid plan?OSS Monty itself is MIT licensed and free to install as a package; Full Monty is the separate commercial hosted version if you want a managed WebSocket service instead.
How much faster is Monty than a container-based sandbox?A fresh OSS Monty sandbox starts in under 1ms from a running pool (about 2ms for Full Monty), compared to roughly 1500ms for a typical container sandbox service.
How does Monty relate to Pydantic AI?Monty powers the 'Code Mode' feature in Pydantic AI and is one piece of the broader Pydantic Stack, alongside Pydantic Logfire and the Logfire AI Gateway.
Can I run Full Monty myself?Full Monty is Pydantic's commercial offering: the same sandbox workers packaged as a container image and exposed behind a WebSocket API, rather than something you self-host from source.
How does Monty compare to Docker, Pyodide, or WASI sandboxes?The documentation includes a direct comparison to those alternatives, arguing Monty avoids their container startup latency, complexity, and cost while still isolating AI-generated code.
What are similar projects?daytona, SPACE, smolvm, CubeSandbox, moejs, box, OpenSandbox, quicksand
Creator
pydantic
Size
18.6 MB
Stars
8.7K
Age
3y
Commits · 90 Days