pydantic/monty

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

What it solves

Monty provides a high-performance, secure sandbox for executing Python code generated by AI models. It eliminates the need for heavy containers, virtual machines, or external sandboxing services, which often introduce significant latency when starting up and running commands.

How it works

Written in Rust, Monty is a Python interpreter VM that enforces memory, time, and recursion limits directly within the VM. It creates a complete isolation layer where the filesystem, environment variables, and network are unavailable by default. The sandbox only interacts with the host system through specifically provided functions and mounts, ensuring that AI-generated code cannot access unauthorized host resources.

Who it’s for

Developers building AI agents or applications that require the ability to run AI-generated Python code safely and efficiently at scale.

Highlights

  • Ultra-low latency: Starts and runs commands in approximately 5ms, compared to hundreds or thousands of milliseconds for Docker or sandboxing services.
  • State persistence: A paused interpreter can be serialized to bytes and resumed later.
  • Multi-language support: Provides official bindings for Python, JavaScript/TypeScript, and Rust.
  • Strict isolation: No native access to the filesystem, network, or environment variables within the sandbox.

Related

  • Project
  • Project
  • Project
  • Project
  • Project