RepoPilot

pydantic/monty

A minimal, secure Python interpreter written in Rust for use by AI

Healthy

Healthy across the board

HealthyDependency

Permissive license, no critical CVEs, actively maintained — safe to depend on.

HealthyFork & modify

Has a license, tests, and CI — clean foundation to fork and modify.

HealthyLearn from

Documented and popular — useful reference codebase to read through.

HealthyDeploy as-is

No critical CVEs, sane security posture — runnable as-is.

  • Last commit today
  • 19 active contributors
  • Distributed ownership (top contributor 42% of recent commits)
  • MIT licensed
  • CI configured
  • Tests present

Computed from maintenance signals — commit recency, contributor breadth, bus factor, license, CI, tests

Informational only. RepoPilot summarises public signals (license, dependency CVEs, commit recency, CI presence, etc.) at the time of analysis. Signals can be incomplete or stale. Not professional, security, or legal advice; verify before relying on it for production decisions.

Embed the "Healthy" badge

Paste into your README — live-updates from the latest cached analysis.

Variant:
RepoPilot: Healthy
[![RepoPilot: Healthy](https://repopilot.app/api/badge/pydantic/monty)](https://repopilot.app/r/pydantic/monty)

Paste at the top of your README.md — renders inline like a shields.io badge.

Preview social card

This card auto-renders when someone shares https://repopilot.app/r/pydantic/monty on X, Slack, or LinkedIn.

Ask AI about pydantic/monty

Grounded in the actual source code. Pick a starter question or write your own.

Or write your own question →

Onboarding doc

Onboarding: pydantic/monty

Generated by RepoPilot · 2026-06-24 · Source

🎯Verdict

GO — Healthy across the board

  • Last commit today
  • 19 active contributors
  • Distributed ownership (top contributor 42% of recent commits)
  • MIT licensed
  • CI configured
  • Tests present

<sub>Computed from maintenance signals — commit recency, contributor breadth, bus factor, license, CI, tests</sub>

TL;DR

Monty is a sandboxed, snapshotable Python interpreter written in Rust that executes Python code with microsecond startup times and zero access to the host filesystem, network, or environment variables. It's designed specifically for LLM agents to safely execute code without container overhead, offering runtime performance within 5x of CPython while maintaining strict security boundaries through controlled external function calls. Rust workspace monorepo with core engine in crates/monty/, CLI wrapper in crates/monty-cli/, Python bindings in crates/monty-python/, JavaScript bindings in crates/monty-js/, type-checking support in crates/monty-type-checking/, and fuzzing/benchmarking in crates/fuzz/ and crates/monty-bench/. Integration with Ruff parser and Ty type-checker via git dependencies.

👥Who it's for

AI engineers and LLM platform developers who need to safely execute agent-generated Python code with ultra-low latency; Rust developers embedding Python execution in production systems without CPython dependencies; teams building agentic workflows requiring snapshotable interpreter state.

🌱Maturity & risk

Experimental and actively developed (marked 'Experimental' in README, workspace version 0.0.17). Well-structured with CI/CD via GitHub Actions (.github/workflows/ci.yml), coverage tracking (codecov integration), and benchmarking infrastructure (crates/monty-bench). However, the 0.0.x version and explicit experimental notice indicate it's not production-ready; APIs and behavior may change.

Early-stage project (v0.0.17) means breaking changes are likely and feature completeness is uncertain. Single primary author (Samuel Colvin) visible in workspace metadata presents maintainability risk. Dependency on Ruff/Ty git revisions (fixed SHAs in Cargo.toml) rather than published versions could create supply-chain fragility. Python subset support is intentionally limited—not all Python code will run.

Active areas of work

Active development with CI/CD pipelines for performance tracking (codspeed.yml), fuzzing infrastructure (string_input_panic, tokens_input_panic targets), and PGO-optimized wheel builds (.github/actions/build-pgo-wheel/). Skills documented in .claude/skills/ suggest ongoing work on coverage analysis, Python playground, and fastmod tooling.

🚀Get running

git clone https://github.com/pydantic/monty.git
cd monty
cargo build --release
cargo run --bin monty-cli -- --help

Requires Rust 1.95+ (per rust-version in Cargo.toml). For Python bindings, build crates/monty-python with maturin develop.

Daily commands:

# Build and test
cargo test
cargo test --all

# Run CLI interpreter
cargo run --bin monty-cli

# Run benchmarks
cargo bench -p monty-bench

# Type checking (uses Ty)
cargo run --bin monty-type-check -- script.py

Makefile present but primarily for CI orchestration.

🗺️Map of the codebase

  • crates/monty/src/lib.rs — Core interpreter library—the primary interface and evaluation engine that all bindings depend on.
  • crates/monty-python/src/lib.rs — Python extension entry point that bridges Rust core to CPython, required for understanding the Python binding layer.
  • crates/monty-js/src/lib.rs — JavaScript/WASM binding layer that exposes the interpreter to Node.js and browser environments.
  • crates/monty-cli/src/main.rs — Command-line interface entry point demonstrating the interpreter's public API and basic usage patterns.
  • Cargo.toml — Workspace configuration defining all member crates, dependencies, and version scheme for the entire monorepo.
  • README.md — Project overview describing Monty's purpose as a minimal, secure Python interpreter for AI use cases.

🧩Components & responsibilities

  • Core Interpreter (crates/monty) (Rust, custom lexer/parser, recursive evaluator) — Lexical analysis, parsing, type inference, and bytecode-like evaluation of Python AST.
    • Failure mode: Panics on malformed input or internal logic errors; returns RuntimeError for user code violations.
  • Python Binding (crates/monty-python) (PyO3, CPython C API) — Exposes interpreter as a CPython extension module; converts Python objects to/from Rust types.
    • Failure mode: Python exceptions propagate; GIL contention if called from multiple threads.
  • JavaScript/WASM Binding (crates/monty-js) (wasm-bindgen, WASM, TypeScript) — Compiles interpreter to WebAssembly; provides TypeScript API for browser and Node.js.
    • Failure mode: JavaScript exceptions; WASM memory exhaustion causes OOM in host process.
  • CLI Tool (crates/monty-cli) (Rust, clap (CLI parsing)) — Standalone executable for testing and ad-hoc Python code evaluation.
    • Failure mode: Exit with non-zero code on evaluation errors; prints error messages to stderr.

🔀Data flow

  • User code stringTokenizer — Raw Python source is split into tokens (identifiers, keywords, operators, literals).

🛠️How to make changes

Add a new built-in Python function or module

  1. Define the function signature and semantics in the core interpreter (crates/monty/src/lib.rs)
  2. Implement the evaluation logic in the interpreter's built-in function handler (crates/monty/src/lib.rs)
  3. Add corresponding Python binding export in PyO3 module (crates/monty-python/src/lib.rs)
  4. Export WASM binding for JavaScript if needed (crates/monty-js/src/lib.rs)
  5. Add test cases for the new function (crates/monty-js/__test__/basic.spec.ts)

Add a new security limit or constraint

  1. Define the limit constant and enforcement logic in the core interpreter (crates/monty/src/lib.rs)
  2. Expose the limit configuration through Python binding (crates/monty-python/src/lib.rs)
  3. Expose through WASM/JavaScript binding (crates/monty-js/src/limits.rs)
  4. Add test cases validating limit enforcement (crates/monty-js/__test__/limits.spec.ts)

Integrate a new host filesystem capability (mount)

  1. Implement mount logic in the core interpreter's file I/O handler (crates/monty/src/lib.rs)
  2. Add mount configuration support in Python binding (crates/monty-python/src/lib.rs)
  3. Implement WASM mount binding (crates/monty-js/src/mount.rs)
  4. Add mount tests and examples (crates/monty-js/__test__/mount.spec.ts)

🔧Why these technologies

  • Rust + RustPython/similar interpreter — Provides memory safety, high performance, and small footprint suitable for embedding in AI systems and serverless environments.
  • PyO3 for Python bindings — Enables zero-copy interop with CPython and allows seamless integration with the Python data science ecosystem.
  • WebAssembly (WASM) for JavaScript binding — Allows browser and Node.js execution with near-native performance and isolation from the host JavaScript engine.
  • Workspace-based Cargo monorepo — Simplifies version management and dependency sharing across multiple binding targets (CLI, Python, JavaScript) with a single build system.

⚖️Trade-offs already made

  • Minimal Python subset vs. full CPython compatibility

    • Why: Reduces attack surface, memory footprint, and startup time—critical for AI deployment scenarios.
    • Consequence: Some Python stdlib modules and advanced features are not available; user code must be compatible with the supported subset.
  • Sandboxed execution by default with explicit mount-based filesystem access

    • Why: Prevents unauthorized file access and resource exhaustion by default, securing AI inference pipelines.
    • Consequence: More verbose setup required for scenarios that need host filesystem integration; requires explicit mount configuration.
  • Single-threaded, synchronous core with async wrapper at the binding layer

    • Why: Simplifies correctness and safety guarantees; async support delegated to host runtimes.
    • Consequence: Interpreter is inherently blocking; long-running computations must be managed by the host with timeouts.

🚫Non-goals (don't propose these)

  • Full CPython compatibility—this is a minimal subset interpreter, not a CPython reimplementation.
  • Real-time execution guarantees—designed for AI inference, not hard real-time systems.
  • Direct network access—I/O is restricted to mounted filesystems and controlled host callbacks.
  • Module distribution via PyPI as full-featured package—primarily a library for embedding and AI use.

🪤Traps & gotchas

Rust edition 2024: Requires nightly or specific toolchain configuration (see .rust-version). Git dependencies: Ruff/Ty dependencies are pinned to specific git SHAs (rev: 6ded4bed...) not published crates—offline builds or git access required. Python subset limitations: Not all Python is supported; code that works in CPython may fail in Monty with no fallback. Snapshot format stability: State serialization may change across versions with no forward compatibility guaranteed (0.0.x phase). PGO profiling: Release builds use lto = "fat" and codegen-units = 1—full rebuilds are slow; use incremental dev builds for iteration.

🏗️Architecture

💡Concepts to learn

  • Snapshot/Serialization — Core feature allowing interpreter state to be frozen to bytes and resumed later—critical for AI workflow persistence and distributed execution
  • Sandbox / Capability-based Security — Monty blocks all host access (filesystem, network, env vars) by default and only exposes functions the developer explicitly allows—essential for safely running untrusted LLM code
  • Abstract Syntax Tree (AST) Interpretation — Monty interprets Python AST from Ruff directly rather than compiling to bytecode, enabling precise control and interception at the syntax level
  • Foreign Function Interface (FFI) — Monty's ability to call Rust/host functions and be called from Python/JS/Rust requires careful FFI design across language boundaries
  • Profile-Guided Optimization (PGO) — Release builds use PGO (lto="fat", codegen-units=1) to maximize runtime performance—critical for achieving near-CPython speed
  • Semantic Type Checking with Ty — Integration with Ruff's Ty module enables full Python type hint support; allows static validation of agent-generated code before execution
  • Memory-Safe Interpreter via Rust — Using Rust instead of C eliminates buffer overflows and memory unsafety; fuzzing infrastructure (crates/fuzz/) validates no panics on malicious input
  • astral-sh/ruff — Direct upstream dependency for Python parsing and AST—Monty consumes Ruff's parser and semantic analysis via git pins
  • astral-sh/ty — Provides Python type-checking engine integrated into Monty for full type hint support within the sandbox
  • RustPython/RustPython — Alternative Python interpreter in Rust with broader language coverage but heavier footprint; comparison point for feature/performance tradeoffs
  • google/pytype — Standalone Python type checker that inspired Monty's type-checking approach; shows ecosystem of Python semantic analysis tools
  • pydantic/pydantic — Sibling Pydantic project; Monty targets AI agents that may use Pydantic for validation, and Pydantic developers are target users

🪄PR ideas

To work on one of these in Claude Code or Cursor, paste: Implement the "<title>" PR idea from CLAUDE.md, working through the checklist as the task list.

Add comprehensive integration tests for monty-js TypeScript bindings

The crates/monty-js/test directory has test files for basic, async, exceptions, inputs, limits, mount, print, repl, serialize, start, type_check, and types functionality, but there's no visible test for error handling edge cases or performance limits under concurrent execution. Given this is a WASM/Node.js binding to a Rust interpreter, adding stress tests and concurrency tests would catch subtle race conditions and ensure the JS API is production-ready for AI use cases.

  • [ ] Create crates/monty-js/test/concurrency.spec.ts to test parallel Python execution
  • [ ] Create crates/monty-js/test/memory-limits.spec.ts to verify memory constraints under stress
  • [ ] Add tests for cleanup and resource disposal in long-running REPL sessions
  • [ ] Document expected behavior in crates/monty-js/README.md for these edge cases

Add fuzzing targets for the Python parser/interpreter boundary

The crates/fuzz directory only has two targets (string_input_panic.rs and tokens_input_panic.rs), both checking for panics. This is a security-critical project for AI use ('secure Python interpreter'), but there are no fuzzing targets that verify correctness of execution results, validate that output matches CPython, or fuzz the VM's memory safety under malicious bytecode. Adding differential fuzzing against CPython would significantly improve security confidence.

  • [ ] Create crates/fuzz/fuzz_targets/execute_diff.rs to compare Monty vs CPython execution on random valid Python
  • [ ] Create crates/fuzz/fuzz_targets/bytecode_exec.rs to fuzz direct bytecode execution paths
  • [ ] Update crates/fuzz/Cargo.toml to include new fuzz targets in the [[bin]] sections
  • [ ] Document fuzzing strategy in a new FUZZING.md file

Add missing GitHub Actions workflow for WASM/npm package publishing

The .github/workflows directory has ci.yml, codspeed.yml, and init-npm-packages.yml, but there's no automated release workflow for publishing crates/monty-js to npm. Given the workspace version is centrally managed (0.0.17) in Cargo.toml and this is a Python package intended for AI use (likely high frequency updates), automating the npm publish pipeline would reduce release friction and ensure version consistency between Rust and JS ecosystems.

  • [ ] Create .github/workflows/npm-publish.yml to build, test, and publish crates/monty-js on version tag
  • [ ] Add logic to detect version bumps from Cargo.toml and automatically update crates/monty-js/package.json
  • [ ] Include npm provenance/OIDC signing for security
  • [ ] Update RELEASING.md with step-by-step npm release instructions

🌿Good first issues

  • Add snapshot persistence tests: crates/monty-cli/tests/ lacks dedicated test coverage for the snapshot/resume feature advertised in README. Create integration tests in tests/snapshots.rs that verify interpreter state can be serialized, written to disk, and resumed with identical results.
  • Document Python stdlib coverage: Create a STDLIB.md file mapping which standard library modules are available in Monty vs. blocked by sandbox restrictions. Audit crates/monty/src/ for stdlib implementation completeness and add test cases for common import patterns.
  • Expand fuzzing harness: crates/fuzz/fuzz_targets/ has only string_input_panic and tokens_input_panic; add a third fuzzer for bytecode generation edge cases (fuzz_targets/bytecode_input_panic.rs) to catch interpreter panics on malformed code.
  • Add benchmarks for external function calls: crates/monty-bench/benches/main.rs lacks latency measurements for host->interpreter->host round-trips; add benchmark cases showing snapshot serialization overhead and FFI call costs.

Top contributors

Click to expand

📝Recent commits

Click to expand
  • ffd29f0 — Add dart/flutter bindings (#414) (runyaga)
  • 3690c51 — reject reusing an already-awaited external future via gather (#420) (rsr5)
  • d9e4c25 — implement "trial deletion" GC to collect cycles (#407) (davidhewitt)
  • 8a0a499 — fix: avoid panic when list.sort() key callback mutates the list (#413) (SAY-5)
  • 0cf24c3 — cache the hash value of interned / static strings (#418) (davidhewitt)
  • 1eb0664 — fix no active frame panic on duplicate coroutine in gather (#410) (rsr5)
  • dec2cbc — fix lifetimes from conflicting merges to main (#417) (davidhewitt)
  • 8ac00de — merge lifetimes in VM to a single lifetime (#416) (davidhewitt)
  • 9f79b5d — Add gc.collect() function only with test-hooks feature (#398) (davidhewitt)
  • 1e7e9d6 — ci: fix lint failures from nightly clippy (#415) (davidhewitt)

🔒Security observations

The Monty project demonstrates a security-conscious approach as a minimal Python interpreter designed for AI use with sandboxing capabilities. Key strengths include use of Rust for memory safety, inclusion of fuzzing tests, and modular architecture. However, several concerns exist: (1) reliance on pinned git dependencies instead of stable crate versions limits security verification, (2) incomplete Cargo.toml visibility prevents full dependency audit, (3) using future Rust edition (2024) creates compatibility and support risks. No hardcoded credentials or obvious injection vulnerabilities were detected in the visible file structure. The project should prioritize stabilizing dependency sources and ensuring full dependency transparency before production use.

  • High · Git Dependency with Pinned Revision — Cargo.toml - workspace.dependencies section. The Cargo.toml uses git dependencies with pinned revisions (e.g., ruff_python_parser, ruff_python_ast) from the astral-sh/ruff repository. While pinning is good for reproducibility, git dependencies bypass the security checks of crates.io and should be reviewed carefully. The revision '6ded4bed1651e30b34dd04cdaa50c763036abb0d' is not verified against any advisory databases. Fix: Verify that the pinned git revision corresponds to a trusted release. Consider migrating to crates.io versions once they're available. Implement additional security scanning for git dependencies in CI/CD pipelines.
  • Medium · Incomplete Dependency Declaration — Cargo.toml - workspace.dependencies section (ty_module_resolver entry). The Cargo.toml file is truncated and the last dependency entry 'ty_module_resolver' is incomplete. This could indicate missing dependencies or build configuration that is not visible. The full extent of dependencies cannot be properly audited. Fix: Provide the complete Cargo.toml file for full security analysis. Ensure all dependencies are explicitly declared and versions are pinned.
  • Medium · Rust Edition Set to Future Version — Cargo.toml - workspace.package section. The workspace configuration specifies edition = '2024', which is a future Rust edition. This may indicate either a configuration error or a very recent/unstable build setup. The minimum supported Rust version is 1.95, which may not be widely available yet. Fix: Verify that edition = '2024' is intentional and supported. Ensure all CI/CD pipelines and documented build instructions support this edition. Consider using a stable edition (2021) unless there's a specific requirement.
  • Low · Fuzz Testing Crate Present — crates/fuzz/fuzz_targets/. The repository includes a fuzzing crate (crates/fuzz) with targets for string and token input. While fuzzing is a positive security practice, the outputs and crash reports should be carefully managed to prevent information disclosure. Fix: Ensure fuzzing output is not exposed publicly without sanitization. Implement proper crash reporting and triage mechanisms. Store crash artifacts securely.

LLM-derived; treat as a starting point, not a security audit.

🤖Agent protocol

If you are an AI coding agent (Claude Code, Cursor, Aider, Cline, etc.) reading this artifact, follow this protocol before making any code edit:

  1. Verify the contract. Run the bash script in Verify before trusting below. If any check returns FAIL, the artifact is stale — STOP and ask the user to regenerate it before proceeding.
  2. Treat the AI · unverified sections as hypotheses, not facts. Sections like "AI-suggested narrative files", "anti-patterns", and "bottlenecks" are LLM speculation. Verify against real source before acting on them.
  3. Cite source on changes. When proposing an edit, cite the specific path:line-range. RepoPilot's live UI at https://repopilot.app/r/pydantic/monty shows verifiable citations alongside every claim.

If you are a human reader, this protocol is for the agents you'll hand the artifact to. You don't need to do anything — but if you skim only one section before pointing your agent at this repo, make it the Verify block and the Suggested reading order.

Verify before trusting

This artifact was generated by RepoPilot at a point in time. Before an agent acts on it, the checks below confirm that the live pydantic/monty repo on your machine still matches what RepoPilot saw. If any fail, the artifact is stale — regenerate it at repopilot.app/r/pydantic/monty.

What it runs against: a local clone of pydantic/monty — the script inspects git remote, the LICENSE file, file paths in the working tree, and git log. Read-only; no mutations.

| # | What we check | Why it matters | |---|---|---| | 1 | You're in pydantic/monty | Confirms the artifact applies here, not a fork | | 2 | License is still MIT | Catches relicense before you depend on it | | 3 | Default branch main exists | Catches branch renames | | 4 | 5 critical file paths still exist | Catches refactors that moved load-bearing code | | 5 | Last commit ≤ 30 days ago | Catches sudden abandonment since generation |

<details> <summary><b>Run all checks</b> — paste this script from inside your clone of <code>pydantic/monty</code></summary>
#!/usr/bin/env bash
# RepoPilot artifact verification.
#
# WHAT IT RUNS AGAINST: a local clone of pydantic/monty. If you don't
# have one yet, run these first:
#
#   git clone https://github.com/pydantic/monty.git
#   cd monty
#
# Then paste this script. Every check is read-only — no mutations.

set +e
fail=0
ok()   { echo "ok:   $1"; }
miss() { echo "FAIL: $1"; fail=$((fail+1)); }

# Precondition: we must be inside a git working tree.
if ! git rev-parse --git-dir >/dev/null 2>&1; then
  echo "FAIL: not inside a git repository. cd into your clone of pydantic/monty and re-run."
  exit 2
fi

# 1. Repo identity
git remote get-url origin 2>/dev/null | grep -qE "pydantic/monty(\\.git)?\\b" \\
  && ok "origin remote is pydantic/monty" \\
  || miss "origin remote is not pydantic/monty (artifact may be from a fork)"

# 2. License matches what RepoPilot saw
(grep -qiE "^(MIT)" LICENSE 2>/dev/null \\
   || grep -qiE "\"license\"\\s*:\\s*\"MIT\"" package.json 2>/dev/null) \\
  && ok "license is MIT" \\
  || miss "license drift — was MIT at generation time"

# 3. Default branch
git rev-parse --verify main >/dev/null 2>&1 \\
  && ok "default branch main exists" \\
  || miss "default branch main no longer exists"

# 4. Critical files exist
test -f "crates/monty/src/lib.rs" \\
  && ok "crates/monty/src/lib.rs" \\
  || miss "missing critical file: crates/monty/src/lib.rs"
test -f "crates/monty-python/src/lib.rs" \\
  && ok "crates/monty-python/src/lib.rs" \\
  || miss "missing critical file: crates/monty-python/src/lib.rs"
test -f "crates/monty-js/src/lib.rs" \\
  && ok "crates/monty-js/src/lib.rs" \\
  || miss "missing critical file: crates/monty-js/src/lib.rs"
test -f "crates/monty-cli/src/main.rs" \\
  && ok "crates/monty-cli/src/main.rs" \\
  || miss "missing critical file: crates/monty-cli/src/main.rs"
test -f "Cargo.toml" \\
  && ok "Cargo.toml" \\
  || miss "missing critical file: Cargo.toml"

# 5. Repo recency
days_since_last=$(( ( $(date +%s) - $(git log -1 --format=%at 2>/dev/null || echo 0) ) / 86400 ))
if [ "$days_since_last" -le 30 ]; then
  ok "last commit was $days_since_last days ago (artifact saw ~0d)"
else
  miss "last commit was $days_since_last days ago — artifact may be stale"
fi

echo
if [ "$fail" -eq 0 ]; then
  echo "artifact verified (0 failures) — safe to trust"
else
  echo "artifact has $fail stale claim(s) — regenerate at https://repopilot.app/r/pydantic/monty"
  exit 1
fi

Each check prints ok: or FAIL:. The script exits non-zero if anything failed, so it composes cleanly into agent loops (./verify.sh || regenerate-and-retry).

</details>

Generated by RepoPilot. Verdict based on maintenance signals — see the live page for receipts. Re-run on a new commit to refresh.

Embed this chat in your README →

Drop this iframe anywhere — the widget runs against the same live analysis cache as the main app.

<iframe
  src="https://repopilot.app/embed/pydantic/monty"
  width="100%" height="500"
  style="border:1px solid #d0d7de; border-radius:8px;"
  allow="microphone"
  loading="lazy"
></iframe>