DSPy CodeInterpreter implementation using Monty, a secure Python interpreter written in Rust
Project description
dspy-monty-interpreter
DSPy CodeInterpreter implementation using Monty, a secure Python interpreter written in Rust.
The Monty team points out, "This project is still in development, and not ready for the prime time." It uses a small subset of the standard library (sys, os, typing, asyncio, re, datetime, json) and can't yet define classes or use match statements.
That said: Monty is fast. For many RLM use cases, Monty is my daily driver.
Installation
pip install dspy-monty-interpreter
Requires pydantic-monty>=0.0.10.
Usage
import dspy
from dspy_monty_interpreter import MontyInterpreter
interpreter = MontyInterpreter()
rlm = dspy.RLM("context -> answer", interpreter=interpreter)
result = rlm(context="What is 2 + 2?")
Standalone usage
from dspy_monty_interpreter import MontyInterpreter
interp = MontyInterpreter()
# Basic execution
interp.execute("x = 42")
interp.execute("print(x + 8)") # returns "50"
# State persists across calls
interp.execute("def double(n):\n return n * 2")
interp.execute("double(21)") # returns "42"
# With tools
def lookup(key: str) -> str:
return "some value"
interp = MontyInterpreter(tools={"lookup": lookup})
interp.execute('result = lookup(key="foo")\nprint(result)')
Filesystem mounts
Filesystem access is disabled by default. Use mounts= to expose a host
directory to sandboxed code under a virtual path:
from dspy_monty_interpreter import MontyInterpreter, MountDirectory
# Read-only mount: sandbox can read but not write
interp = MontyInterpreter(
mounts=MountDirectory("/data", "/host/path/to/data", mode="read-only")
)
interp.execute("from pathlib import Path\nPath('/data/input.csv').read_text()")
# Overlay mount: reads fall through to host; writes stay in memory
interp = MontyInterpreter(
mounts=MountDirectory("/work", "/host/project", mode="overlay")
)
Modes: "read-only", "read-write", "overlay". Pass a list of
MountDirectory for multiple mount points.
Why Monty?
- Fast: Microsecond startup (no subprocess, no WASM bootstrap)
- Secure: No network or environment access; filesystem access is opt-in via mounts
- Lightweight: Pure Rust, no Deno/Pyodide dependency
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dspy_monty_interpreter-0.2.0.tar.gz.
File metadata
- Download URL: dspy_monty_interpreter-0.2.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97657536a3b4f069b6f1a32f02545191147bb68d4c339cf03dd1e781e0a25f5a
|
|
| MD5 |
5f3c22bd8ac47eb50ab51fc5e764f0a8
|
|
| BLAKE2b-256 |
b3fc6556e5183fe231b5b96e4798302f0ed0c12414db1e6736c5c164d7b7e923
|
File details
Details for the file dspy_monty_interpreter-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dspy_monty_interpreter-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a2fe2b13ca6b8b31e3514d43e4633dbf46beea48d1f9f2a0682a4c21b65b236
|
|
| MD5 |
9f81d29e363bf0ddac8223112135a8fe
|
|
| BLAKE2b-256 |
0dde14e9e433734d9db76dd2dc040cc34799c2662e90662bd3904aefc9c828b9
|