--- id: pydantic-monty version: "0.0.21" license: MIT license_treatment: permissive maintenance: active --- # pydantic-monty — The Monty sandboxed Python interpreter: bindings plus the worker binary License: permissive · Maintenance: active · Downloads: 3.4M/mo ## 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 above — 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 pip install pydantic-monty uv add pydantic-monty poetry add pydantic-monty ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 3.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags sandboxed python execution, untrusted code isolation, subprocess worker pool, safe code evaluation, python sandbox interpreter, crash-proof code runner, resource-limited execution, sandboxing, security-isolation, async-support [View on SkillFed](https://skillfed.io/packages/pydantic-monty) · [View on PyPI](https://pypi.org/project/pydantic-monty/)