# pydantic/monty

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/pydantic-monty).**

5,540 stars · 201 forks · Rust · mit

## Links

- GitHub: https://github.com/pydantic/monty
- awesome-repositories: https://awesome-repositories.com/repository/pydantic-monty.md

## Description

Monty is a sandboxed execution environment designed primarily for running Python code generated by AI models. It provides a secure, isolated runtime that blocks host access, enforces resource limits, and supports pre-execution type checking against built-in type hints to catch signature mismatches before code runs. The sandbox can persist its interpreter state at external function calls, allowing execution sessions to be serialized, stored, and later resumed from a file or database.

What distinguishes Monty is its combination of stateful, resumable execution with multi-language native embedding. The runtime exposes itself as native libraries via FFI for Rust, Python, and JavaScript, giving each language identical behavior when embedding the sandbox engine. It also mounts host directories into a virtual filesystem with configurable access rights and path normalization that prevents escape. Host function access is explicitly whitelisted, so executed code can only interact with approved external functions, enabling secure integration of AI-generated tool calls. Each request runs in a separate process with automatic worker replacement on crash, ensuring one response per request.

The sandbox covers the full lifecycle of AI-generated code execution: type-checking, sandboxed execution, state snapshotting, and persistence for later re-execution. It is built in Rust and provides native bindings that make it embeddable in Rust, Python, or JavaScript applications.

## Tags

### Development Tools & Productivity

- [Python Execution Sandboxes](https://awesome-repositories.com/f/development-tools-productivity/isolated-execution-environments/python-execution-sandboxes.md) — Executes AI-generated Python code in isolated subprocess workers with resource limits and no host access.
- [Multi-Language Bindings](https://awesome-repositories.com/f/development-tools-productivity/compilers-toolchains/c-extension-interfaces/multi-language-bindings.md) — Creates native bindings for Rust, Python, and JavaScript that allow each language to call the embedded sandbox engine. ([source](https://github.com/pydantic/monty#readme))

### Artificial Intelligence & ML

- [Code Execution Environments](https://awesome-repositories.com/f/artificial-intelligence-ml/code-execution-environments.md) — Provides a sandboxed environment specifically for executing Python code produced by AI models with resource limits and no host access.
- [Interpreter State Snapshots](https://awesome-repositories.com/f/artificial-intelligence-ml/stateful-agent-orchestration/global-run-local-state/stateful-run-executions/execution-snapshots/interpreter-state-snapshots.md) — Captures the Python interpreter state at function calls and restores it later for persistent, resumable execution sessions.
- [Interpreter State Snapshots](https://awesome-repositories.com/f/artificial-intelligence-ml/stateful-agent-orchestration/global-run-local-state/stateful-run-executions/execution-snapshots/runtime-state-snapshots/interpreter-state-snapshots.md) — Captures Python interpreter state at function calls to enable persistent, resumable execution sessions. ([source](https://github.com/pydantic/monty#readme))

### Part of an Awesome List

- [Code Execution Environments](https://awesome-repositories.com/f/awesome-lists/ai/code-execution-environments.md) — Provides an isolated runtime specifically designed for executing code generated by AI models in a secure manner. ([source](https://github.com/pydantic/monty/blob/main/README.md))
- [Type Checking](https://awesome-repositories.com/f/awesome-lists/devtools/type-checking.md) — Runs full type-checking on Python code before or during execution using built-in type hints. ([source](https://github.com/pydantic/monty#readme))
- [Pre-Execution Type Checks](https://awesome-repositories.com/f/awesome-lists/devtools/type-checking/pre-execution-type-checks.md) — Runs full Python type-checking against built-in type hints before code execution to catch signature mismatches early.
- [Artificial Intelligence](https://awesome-repositories.com/f/awesome-lists/ai/artificial-intelligence.md) — Secure Python interpreter for sandboxed LLM-generated code execution.

### Data & Databases

- [Execution State Persistence](https://awesome-repositories.com/f/data-databases/execution-state-persistence.md) — Persists parsed code and runner settings so they can be loaded and re-executed later across sessions. ([source](https://github.com/pydantic/monty/blob/main/README.md))
- [Virtual Directory Mounts](https://awesome-repositories.com/f/data-databases/file-storage-systems/filesystem-mounts/mount-namespace-virtualization/tmpfs-root-sandbox-execution/virtual-directory-mounts.md) — Mounts host directories into the sandbox with configurable access rights and path normalization that prevents escape. ([source](https://github.com/pydantic/monty/blob/main/CLAUDE.md))
- [Tmpfs Root Sandboxing](https://awesome-repositories.com/f/data-databases/file-storage-systems/filesystem-mounts/mount-namespace-virtualization/tmpfs-root-sandboxing.md) — Mounts host directories into a virtual sandbox filesystem with configurable access rights and path normalization that prevents escape.

### DevOps & Infrastructure

- [Code Execution Sandboxes](https://awesome-repositories.com/f/devops-infrastructure/execution-environments/code-execution-runtimes/code-execution-sandboxes.md) — Runs untrusted code in a secure, isolated sandbox that blocks host access, enforces resource limits, and returns output and errors. ([source](https://github.com/pydantic/monty#readme))
- [Container Directory Mounting](https://awesome-repositories.com/f/devops-infrastructure/volume-mounts/host-guest-mounts/container-directory-mounting.md) — Binds host directories into the sandbox filesystem with configurable access permissions and path traversal prevention.
- [Worker Process Isolation](https://awesome-repositories.com/f/devops-infrastructure/polling-based-worker-execution/worker-process-isolation.md) — Executes each request in a separate operating system process, automatically replacing crashed workers to ensure reliability.

### Programming Languages & Runtimes

- [Runtime Embedding](https://awesome-repositories.com/f/programming-languages-runtimes/c-library-embedding/runtime-embedding.md) — Integrates a safe code execution engine into larger host applications written in Rust, Python, or JavaScript.
- [Host Function Exposure](https://awesome-repositories.com/f/programming-languages-runtimes/host-function-exposure.md) — Registers only explicitly approved host functions as callable within the sandbox, controlling integration and security.
- [Multi-Language Runtime Bindings](https://awesome-repositories.com/f/programming-languages-runtimes/language-interoperability/interoperability/multi-language-runtime-bindings.md) — Provides native Rust, Python, and JavaScript interfaces to embed the sandbox execution engine into any host application.
- [Multi-Language Runtime Embeddings](https://awesome-repositories.com/f/programming-languages-runtimes/multi-language-runtime-embeddings.md) — Ships native bindings for Rust, Python, and JavaScript to embed the sandbox execution engine identically across languages.

### Security & Cryptography

- [Sandbox State Management Systems](https://awesome-repositories.com/f/security-cryptography/sandboxing/sandbox-state-management-systems.md) — Executes code in an isolated sandbox that persists state to disk or database, allowing sessions to be snapshotted and resumed.

### Software Engineering & Architecture

- [Interpreter](https://awesome-repositories.com/f/software-engineering-architecture/architectural-design-patterns/state-management/persistence-and-serialization/state-serialization/state-snapshots/interpreter.md) — Captures the Python interpreter state at external function calls to enable persistent, resumable execution sessions.
- [Python Type Checkers](https://awesome-repositories.com/f/software-engineering-architecture/static-type-checkers/python-type-checkers.md) — Runs full Python type-checking on AI-generated code before or during execution using built-in type hints.
