A collection of examples showing how to use Pydantic's Monty - from basic expression evaluation to wrapping it as a tool inside the OpenAI Agents SDK.
Monty lets you safely run Python code without containers and with blazingly fast startup times. It supports typed inputs, external function calls, type checking via ty, and serializable interpreter snapshots.
Requires Python ≥ 3.12 and uv.
# Clone the repo
git clone https://github.com/maximilianzuern/monty-examples && cd monty-examples
# Install dependencies
uv sync
# Run first example
uv run examples/basic.py| Example | Description |
|---|---|
| basic.py | Runs a hardcoded simple expression (4242 * 4242). Basically a "hello world". |
| useParams.py | Passes typed input parameters (x, y) into the interpreter and runs an async multiply function. |
| useExternalFunc.py | Defines a host-side multiply function and calls it from inside the sandboxed interpreter. |
| openAIagentSDK.py | Wraps Monty as a tool inside an OpenAI Agents SDK agent that can multiply numbers on demand. |