# monty | Pydantic | Knowledge Base | Instagit

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

GitHub Stars: 5.3k

Repository: https://github.com/pydantic/monty

---

## Articles

### [How to Integrate Monty with Python Using PyO3: A Complete Guide](/pydantic/monty/how-to-integrate-monty-with-python-using-pyo3)

Integrate Monty with Python using PyO3 to leverage a sandboxed Rust interpreter. Explore this comprehensive guide for seamless integration and enhanced performance.

- Tags: how-to-guide
- Published: 2026-02-19

### [How to Define and Register Custom External Functions in Monty: A Complete Guide](/pydantic/monty/how-to-define-and-register-custom-external-functions-in-monty)

Learn how to define and register custom external functions in Monty with this complete guide. Enhance your Monty workflows by easily integrating your own Python implementations.

- Tags: how-to-guide
- Published: 2026-02-16

### [Python Types Supported in Monty: A Complete Guide to the Pydantic Sandbox Runtime](/pydantic/monty/what-python-types-are-supported-in-monty)

Explore Python types supported in Monty. Discover primitives, containers, callables, and standard library types within Pydantic's sandbox runtime for robust data handling.

- Tags: tutorial
- Published: 2026-02-16

### [How Iterative Execution Works in Monty: A Complete Guide to Sandboxed Async Python](/pydantic/monty/how-does-iterative-execution-work-in-monty)

Discover how iterative execution in Monty enables sandboxed async Python. Learn how Monty pauses at external calls and futures, serializes VM state, and resumes execution for seamless integration.

- Tags: deep-dive
- Published: 2026-02-16

### [How Monty Captures stdout and stderr from Executed Python Code](/pydantic/monty/how-does-monty-capture-stdout-stderr-from-executed-code)

Discover how Monty captures stdout and stderr from executed Python code by replacing standard stream objects and using a configurable PrintWriter for flexible output handling.

- Tags: internals
- Published: 2026-02-16

### [Built-in Functions Available in Monty: Complete Guide to the Rust Python Interpreter](/pydantic/monty/which-built-in-functions-are-available-in-monty)

Explore Monty's 35 Rust compiled built-in functions like print len and sum for efficient VM dispatch. Get the complete guide to the Rust Python interpreter.

- Tags: api-reference
- Published: 2026-02-16

### [How Monty Tracks Memory Allocations in Python Objects](/pydantic/monty/how-does-monty-track-memory-allocations)

Discover how Monty tracks memory allocations in Python using a cooperative Heap arena and pluggable ResourceTracker to record statistics and enforce limits.

- Tags: internals
- Published: 2026-02-16

### [How Monty Limits Stack Depth: Function Calls and Data Structure Recursion](/pydantic/monty/how-does-monty-limit-stack-depth)

Discover how Monty limits stack depth using ResourceTracker for function calls and DepthGuard for container operations, preventing recursion errors.

- Tags: internals
- Published: 2026-02-16

### [Python Features Not Supported in Monty: A Complete Guide to Sandbox Limitations](/pydantic/monty/what-python-features-are-not-supported-in-monty)

Explore Python features unsupported in the pydantic Monty sandbox. Understand security limitations including class definitions, pattern matching, and generators.

- Tags: deep-dive
- Published: 2026-02-16

### [How to Use Monty from JavaScript/TypeScript with napi-rs](/pydantic/monty/how-to-use-monty-from-javascript-typescript-with-napi-rs)

Integrate Monty the sandboxed Python interpreter into your JavaScript/TypeScript projects with napi-rs. Install the @pydantic/monty package for seamless Rust-based Python execution.

- Tags: how-to-guide
- Published: 2026-02-16

### [Monty Performance Comparison to CPython: Startup Latency and Execution Speed Analysis](/pydantic/monty/monty-performance-comparison-to-cpython)

Discover the Monty performance comparison to CPython. Analyze microsecond cold-start latency and execution speeds 0.5x to 5x faster than CPython for high-frequency Python execution.

- Tags: performance
- Published: 2026-02-16

### [How Monty's Built-in Type Checking Works: A Deep Dive into the Rust Implementation](/pydantic/monty/how-does-montys-built-in-type-checking-work)

Explore Monty's type checking implementation. Learn how it uses Ruff's ty crates and a Salsa database for efficient Python code analysis across interfaces.

- Tags: deep-dive
- Published: 2026-02-16

### [Monty Sandboxing Security Measures: Complete Isolation for Untrusted Python Code](/pydantic/monty/what-security-measures-does-monty-implement-for-sandboxing)

Discover Monty's complete isolation security for untrusted Python code. Learn how it enforces resource limits and yields OS operations to the host for enhanced safety.

- Tags: deep-dive
- Published: 2026-02-16

### [Monty's Safety Mechanisms for Memory Management: Reference Counting and RAII in a Sandboxed Rust VM](/pydantic/monty/what-are-montys-safety-mechanisms-for-memory-management)

Explore Monty's memory safety mechanisms in its sandboxed Rust VM, featuring reference counting and RAII to prevent leaks and vulnerabilities in untrusted Python code.

- Tags: internals
- Published: 2026-02-16

### [How Monty Implements Async/Await Support: A Deep Dive into the Python Runtime](/pydantic/monty/how-does-monty-implement-async-await-support)

Discover how Monty implements async/await support using a three-layer architecture for syntax parsing, bytecode generation, and an async executor managing coroutines and futures.

- Tags: deep-dive
- Published: 2026-02-16

### [Which Standard Library Modules Are Available in Monty? A Complete Guide to the 5 Built-in Modules](/pydantic/monty/which-standard-library-modules-are-available-in-monty)

Discover the five standard library modules available in Monty: sys, typing, asyncio, pathlib, and os. Learn about Monty's minimal, sandbox-safe API for each module.

- Tags: api-reference
- Published: 2026-02-16

### [How Monty's Serialization Works for Execution State](/pydantic/monty/how-does-montys-serialization-work-for-execution-state)

Discover how Monty serializes execution state. Learn how VM components are captured in VMSnapshot and encoded into a compact binary blob using postcard for later restoration.

- Tags: internals
- Published: 2026-02-16

### [How Monty Handles Reference Counting for Memory Management: A Deep Dive into the Rust Implementation](/pydantic/monty/how-does-monty-handle-reference-counting-for-memory-management)

Explore Monty's reference counting for memory management. Discover how it uses explicit inc_ref and dec_ref operations for deterministic object lifetime control within the Rust implementation.

- Tags: deep-dive
- Published: 2026-02-16

### [How to Configure Monty's Resource Limits: Memory, Time, and Recursion Depth](/pydantic/monty/how-to-configure-montys-resource-limits)

Master Monty's resource limits! Learn to configure max memory, duration, allocations, and recursion depth for robust sandbox execution. Ensure secure and efficient code.

- Tags: how-to-guide
- Published: 2026-02-16

### [Monty Resource Limits: How the Python Sandbox Enforces Security Boundaries](/pydantic/monty/what-resource-limits-does-monty-enforce)

Monty enforces resource limits to secure your Python sandbox. Discover how it caps heap allocations, execution time, memory, and recursion depth.

- Tags: deep-dive
- Published: 2026-02-16

### [How External Function Callbacks Work in Monty: A Complete Technical Guide](/pydantic/monty/how-do-external-function-callbacks-work-in-monty)

Master external function callbacks in Monty. Learn the three-phase round-trip process for securely invoking host Python functions from sandboxed code. Explore this technical guide for detailed insights.

- Tags: deep-dive
- Published: 2026-02-16

### [How Monty's Bytecode VM Executes Python Code: A Deep Dive into the Rust Implementation](/pydantic/monty/how-does-monty-bytecode-vm-execute-python-code)

Discover how Monty's bytecode VM executes Python code using a stack-based model in safe Rust. Explore cached frames, external call pausing, and snapshot features.

- Tags: deep-dive
- Published: 2026-02-16

### [Complete List of Opcodes Supported by Monty's Bytecode VM](/pydantic/monty/what-opcodes-are-supported-by-montys-bytecode-vm)

Explore over 80 opcodes supported by Monty's bytecode VM for stack manipulation, arithmetic, control flow, function calls, async await and exception handling. Get the complete list.

- Tags: api-reference
- Published: 2026-02-16

### [How Monty Implements Its Bytecode VM Architecture: Compiler, Operations, and Execution](/pydantic/monty/how-is-montys-bytecode-vm-architecture-implemented-compiler-operations-execution)

Explore Monty's bytecode VM architecture implementation. Learn how its compiler transforms AST nodes into bytecode, how operations are defined, and how the stack-based VM executes code efficiently.

- Tags: architecture
- Published: 2026-02-16

### [How Monty Type Checking Works with Python Type Hints: A Complete Guide](/pydantic/monty/how-does-montys-built-in-type-checking-support-work-with-python-type-hints)

Discover how Monty utilizes Python type hints for static type checking with its Ruff-based engine. Catch errors before execution with detailed diagnostics.

- Tags: deep-dive
- Published: 2026-02-16

### [How Monty Implements External Function Callbacks and Iterative Execution with start()/resume()](/pydantic/monty/how-does-monty-implement-external-function-callbacks-and-iterative-execution-with-startresume)

Discover how Monty implements external function callbacks and iterative execution using start and resume. Learn to pause, inspect, and resume VM execution with snapshots.

- Tags: internals
- Published: 2026-02-16

### [Monty Resource Limits and Security Controls: A Deep Dive into Sandboxed Execution](/pydantic/monty/what-resource-limits-and-security-controls-does-monty-provide-for-sandboxed-code-execution)

Explore Monty's resource limits and security controls for sandboxed execution. Learn how LimitedTracker intercepts allocations, monitors time, and caps recursion for safe Python code.

- Tags: deep-dive
- Published: 2026-02-16

