+9
Daily
8,933
stars
497
forks
42
watchers
1,083
prs
242
issues
39
releases
README
Monty
A secure Python sandbox, written in Rust, for code written by AI.
______________________________________________________________________
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
Commercial Support, the server that runs the same sandbox behind a gRPC stream as a service.
A new OSS Monty sandbox takes under 1ms from a running pool (Commercial Support: 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
bash
uv add pydantic-monty Python
npm install @pydantic/monty JavaScript / TypeScript
cargo add monty Rust
Commercial Support 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:
python
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
- Introduction with the latency measurements
- Comparison to alternatives: Docker, Pyodide, WASI,
sandboxing services
- Getting started with Python,
JavaScript or
Rust
- Security model, resource
limits,
snapshots, the Python
subset
- docs/: the source of the documentation site
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:
- Pydantic AI - Type-safe
agent framework
- Pydantic Logfire - AI-first,
full-stack observability
- Logfire AI Gateway - Unified
LLM proxyTop issues
#965Discussion: Support for inheritance in user code8 comments · 2026-10-02#499CPU time limits6 comments · 2026-06-11#483MontyRepl time limit (max_duration_secs) is measured from REPL construction, not per feed_run5 comments · 2026-06-02#134Proposal: treat Python type annotations as runtime contracts5 comments · 2026-02-10#739Support common CPython JSON-to-file idiom: json.dumps(default=...) and Path.write_text(encoding=...)4 comments · 2026-08-13#1042Stack overflow in Drop of ruff's AST on large left-associative chains3 comments · 2026-10-14#953Support for BaseModel3 comments · 2026-09-30#948v2: rename MountDir to LocalVolume and configure it at checkout3 comments · 2026-09-27
Latest release
v1.6.0 - 2026-11-11 v1.6.0 2026-11-11What's Changed Wait for departed remote streams on pool close by @strawgate in https://github.com/pydantic/monty/pull/1257 Add exclusive file creation to the filesystem protocol by @tomhoule in https://github.com/pydantic/monty/pull/1245 Require Rust 1.98 so macOS 27 builds load by @dmontagu in https://github.com/pydantic/monty/pull/1259 Convert heap reads to PyValue before protocol dispatch by @jaheba in https://github.com/pydantic/monty/pull/1242 Add a browser_cdp example by @samuelcolvin in https://github.com/pydantic/monty/pull/1244 Preserve remote error details and expose type