skillfed

pydantic-monty

The Monty sandboxed Python interpreter: bindings plus the worker binary

pydantic-monty v0.0.21 3.4M downloads/30d#2,638 on PyPI8,052
Permissive license MIT Active released

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-monty

uv

uv add pydantic-monty

poetry

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 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

Development Status :: 3 - AlphaEnvironment :: MacOS XIntended Audience :: DevelopersIntended Audience :: Information TechnologyIntended Audience :: System AdministratorsOperating System :: Microsoft :: WindowsOperating System :: POSIX :: LinuxOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: ImplementationTopic :: InternetTopic :: Software Development :: Libraries :: Python Modules

Tags

sandboxed python executionuntrusted code isolationsubprocess worker poolsafe code evaluationpython sandbox interpretercrash-proof code runnerresource-limited execution
sandboxingsecurity-isolationasync-support

More Python Modules packages