Monty
Monty is a minimal, secure Python sandbox written in Rust for code written by AI, designed to avoid the latency, complexity, and cost of container-based sandboxes.
Visit pydantic/montyOverview
Monty is a minimal, secure Python sandbox written in Rust for code written by AI. It avoids the latency, complexity, and cost of a container-based sandbox for running LLM-generated code. It is available as OSS Monty, an MIT-licensed Python 3.14 sandbox installed as a package, and as Full Monty, a commercial server that runs the same sandbox behind a gRPC stream.
Key Features
- Low-latency sandboxing: a new OSS Monty sandbox takes under 1 ms from a running pool, and Full Monty takes about 2 ms, compared with around 1500 ms for a sandbox service.
- The sandbox has no filesystem, environment variables, or network; it reaches the host only through functions and mounts passed in.
- Host functions and external lookups let sandboxed code call host-provided tools while seeing only their return values.
- Snapshots allow the whole sandbox state to be dumped to bytes at an external function call or at the end of a REPL snippet, supporting suspend and resume.
- Strict resource limits for maximum memory and execution time are enforced by the VM, so operations such as 'x' * 10**12 raise MemoryError before the allocation is attempted.
- Packages are available for Python, JavaScript/TypeScript, and Rust; commercial Full Monty runs the same workers behind gRPC as a container image with OS-level isolation and horizontal scaling.
Use Cases
- Running Python programs generated by LLMs safely, especially when agents write short programs that call tools rather than making a sequence of individual tool calls.
- Powering Code Mode in Pydantic AI, where generated code needs a safe execution environment.
- Implementing long-running REPL sessions and human-in-the-loop workflows by suspending and resuming sandbox state from bytes.
- Scaling many sandbox workers with minimal cost and complexity because no new VM or container is provisioned for every sandbox.
Getting Started
- Install for Python with uv add pydantic-monty.
- Install for JavaScript or TypeScript with npm install @pydantic/monty.
- Install for Rust with cargo add monty.
- Follow the Python, JavaScript, or Rust quickstarts for next steps.
Deployment & Requirements
- OSS Monty is installed as a package for Python, JavaScript/TypeScript, or Rust and runs in the application's local execution environment.
- Full Monty is a commercial server that runs the same sandbox behind a gRPC stream as a service and is available as a container image for larger-scale deployments with OS-level isolation and horizontal scaling.
Before You Adopt
- License: MIT. Review its terms before using, modifying, or distributing the project.
- The sandbox does not include a filesystem, environment variables, or network by default; access to the host must be supplied explicitly through functions and mounts.
- Monty supports a subset of Python and maintains a limitations section covering known divergences from CPython.
- Full Monty runs code remotely, which the source says reduces the blast radius of an escape and lets sandboxes scale independently of calling hosts.