Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
M

monty

> 编程语言
Open source

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

8.0K stars0 likes2 views
WebsiteGitHub

About

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


[!NOTE] Hack Monty Round 3 is live - the last round before Monty V1. See pydantic.dev/monty for details.

Monty runs Python written by a model with no container, VM or sandboxing service in the loop. Creating a sandbox and running ten commands in it takes 5 ms (Docker: 900 ms, a sandboxing service: 1900 ms), a paused interpreter serialises to bytes you can resume later, and memory, time and recursion limits are enforced by the VM itself. 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

The commercial Full Monty 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 proxy

Issues· 129 open

View all issuesOpen on GitHub
  • #955

    REPL string literals still exhaust the u16 name id space in long-lived sessions

    Updated Sep 30, 2026
  • #947

    v2: default mount mode should be read-only

    enhancementV2Updated Sep 30, 2026
  • #953

    Support for BaseModel

    enhancementUpdated Sep 30, 2026
  • #876

    Parser Crash: NotImplementedError on Yield Expressions - Ungraceful Error Handling

    Updated Sep 28, 2026
  • #941

    Type checker rejects the supported open() builtin

    Updated Sep 27, 2026
  • #948

    v2: rename MountDir to LocalVolume and configure it at checkout

    enhancementV2Updated Sep 27, 2026
  • #480

    Feature request: import Python modules from files in Monty's filesystem (code reuse)

    Updated Sep 27, 2026
  • #939

    Could not compile `ruff_python_ast` because of `salsa`

    Updated Sep 25, 2026
  • #872

    REPL type-check context desyncs from the session namespace: a raising snippet loses its bindings, and imports never carry

    Updated Sep 25, 2026
  • #921

    functools.partial keyword index can terminate a memory-limited worker

    Updated Sep 23, 2026

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言