pydantic-monty
The Monty sandboxed Python interpreter: bindings plus the worker binary
What it is and what it does
Pydantic-monty is a Python sandbox that executes untrusted or adversarial code in isolated worker subprocesses, preventing crashes from corrupting your main process. It wraps the Monty interpreter—a hardened Python runtime—and exposes it via a pool-based API: you check out a session, feed it code snippets, and get results back. State persists across feeds within a session, and the pool transparently replaces any crashed worker.
The package is a metapackage that installs two distributions: pydantic-monty-client (the importable module) and pydantic-monty-runtime (the worker binary). It supports both synchronous and async workflows, with features like snapshots (pausing/resuming execution), resource limits (timeout, cumulative execution time), type checking via bundled ty, and filesystem mounts. External functions can be injected via external_lookup, and execution state can be serialized and restored across processes.
Use it for:
- Execute untrusted user-submitted code (e.g., in a code-evaluation service) without risking the host process.
- Run adversarial or fuzzing inputs against your code in isolation to detect crashes or resource exhaustion.
- Implement a REPL or notebook-like interface where each cell runs in a fresh or persistent sandbox session.
- Checkpoint long-running computations by dumping and restoring execution snapshots across process boundaries.
- Enforce strict resource limits (CPU time, memory) on code execution with transparent worker replacement on timeout.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides Python bindings to execute untrusted Python code in a sandboxed subprocess pool, with crash isolation and resource limits enforced by the Monty interpreter.
Yes, if you need to execute untrusted Python code safely. The package is actively maintained, has no known vulnerabilities, uses a permissive MIT license, and low install friction. It is still in Alpha (Development Status 3), so expect API changes and test thoroughly before production use. Not necessary if you only run trusted code.
Install
pydantic-monty on PyPI
pip
pip install pydantic-montyuv
uv add pydantic-montypoetry
poetry add pydantic-montyInstalling pydantic-monty
Before you install
Low install friction: a pure-Python wheel metapackage that bundles two distributions (pydantic-monty-client and pydantic-monty-runtime). Actively maintained with a release 5 days old and 8052 repository stars.
License in practice
MIT license permits commercial use, modification, and distribution with minimal restrictions—standard permissive terms.
Quickstart
from pydantic_monty import Monty
with Monty() as pool:
with pool.checkout() as session:
result = session.feed_run('1 + 2')
print(result) # 3
Requires Python 3.10 or later; the monty worker binary must be available via MONTY_BIN, binary_path, PATH, or installed via pydantic-monty-runtime.
Verify before relying
- Whether the worker binary is pre-compiled for all supported platforms (macOS, Windows, Linux) or requires build-time setup.
- Performance overhead of subprocess spawning and IPC for typical workloads.
- Exact semantics of crash recovery and whether all memory errors trigger MontyCrashedError.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pydantic-monty-client, pydantic-monty-runtime |
| Maintenance | actively maintained — 5 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 3,394,230/month — #2,638 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pydantic_monty-0.0.21-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
pydantic-monty-runtimeProvides the `monty` command-line binary, a…
permissive · top 15,000 on PyPI
starlark-pyo3Exposes the Starlark interpreter (a Python-like…
unclear · top 15,000 on PyPI
pydantic-evalsPydantic Evals provides a framework for…
permissive · top 5,000 on PyPI
pydantic-ai-harnessPydantic AI Harness provides pre-built…
permissive · top 5,000 on PyPI
montyMonty provides supplementary utility functions…
permissive · top 5,000 on PyPI
pytest-forkedA pytest plugin that runs each test in a forked…
permissive · top 5,000 on PyPI
e2bE2B provides a Python SDK to create and control…
permissive · top 5,000 on PyPI
hyperlight-sandboxHyperlight-sandbox provides a Python API for…
permissive · top 15,000 on PyPI
bounded-pool-executorWraps Python's ProcessPoolExecutor and…
permissive · top 15,000 on PyPI
hyperlight-sandbox-backend-wasmProvides a WebAssembly backend implementation…
permissive · top 15,000 on PyPI