Skip to main content
Monty is intentionally limited to support one specific use case: running code written by agents. This page documents what Python features are not available.
Monty is experimental and not ready for production use. The project is still in active development.

Major Language Limitations

These core Python features are currently not supported:

No Classes (Yet)

Monty does not currently support class definitions.
# ❌ This will NOT work
class MyClass:
    def __init__(self, value):
        self.value = value

    def get_value(self):
        return self.value
Class support is planned and should be added soon. Track progress on the Monty GitHub repository.
What works instead:
# ✅ Use dictionaries and functions
def create_object(value):
    return {'value': value}

def get_value(obj):
    return obj['value']

obj = create_object(42)
print(get_value(obj))

No Match Statements (Yet)

Pattern matching with match/case is not implemented.
# ❌ This will NOT work
match status:
    case 'success':
        return True
    case 'error':
        return False
    case _:
        return None
Match statement support is planned and should be added soon.
What works instead:
# ✅ Use if/elif/else chains
if status == 'success':
    return True
elif status == 'error':
    return False
else:
    return None

# ✅ Or use dictionaries for dispatch
handlers = {
    'success': lambda: True,
    'error': lambda: False,
}
return handlers.get(status, lambda: None)()

Standard Library Limitations

Limited Module Support

Only these stdlib modules are available:
  • sys
  • os
  • typing
  • asyncio
  • re
  • pathlib
Coming soon: datetime, dataclasses, json
# ❌ These imports will FAIL
import math
import random
import collections
import itertools
import functools
import pickle
import socket
import urllib
The rest of the Python standard library is not available and most modules will not be added. Monty is designed for agent code, not general-purpose Python execution.
What works instead:
# ✅ Use built-in functions and supported modules
import sys
import re
from typing import List, Dict

# Basic math operations work without imports
result = abs(-42)
maximum = max([1, 2, 3])
total = sum(range(10))

No Third-Party Libraries

Monty cannot use third-party packages like Pydantic, requests, numpy, etc.
# ❌ This will NEVER work
import pydantic
import requests
import numpy
import pandas
Support for third-party libraries is not a goal for Monty. The interpreter is designed exclusively for sandboxed agent code execution.
Design philosophy: Monty is built for a specific use case where the code is:
  • Written by an LLM/agent
  • Executed in a sandboxed environment
  • Using only built-in and stdlib features
  • Making external calls via host-provided functions

Security Restrictions

These restrictions exist to ensure safe execution of untrusted agent code.

No Direct Filesystem Access

All filesystem operations are sandboxed and controlled by the host.
# ❌ Direct file I/O is blocked by default
with open('data.txt', 'r') as f:
    content = f.read()

# ❌ These also don't work without host permission
import os
os.listdir('.')
os.remove('file.txt')
The host environment must explicitly provide filesystem access through external functions:
# Agent code calls host-provided function
content = read_file('data.txt')  # External function
The host controls:
  • Which files can be accessed
  • What operations are allowed
  • Path validation and sandboxing

No Environment Variables

Direct access to environment variables is blocked.
# ❌ This will not work
import os
api_key = os.environ.get('API_KEY')
What works instead:
# ✅ Host provides config through external functions
api_key = get_config('api_key')  # External function

No Network Access

Sockets, HTTP requests, and all network operations are blocked.
# ❌ These will fail (imports don't exist)
import socket
import urllib.request
import http.client
What works instead:
# ✅ Use host-provided external functions
response = await http_get('https://api.example.com/data')
data = await call_llm(prompt, messages)

No Subprocess Execution

Running external commands or spawning processes is blocked.
# ❌ These don't work (imports don't exist)
import subprocess
import os

os.system('ls')
subprocess.run(['python', 'script.py'])

Resource Limits

Monty enforces strict resource limits to prevent abuse:

Memory Limits

# Agent code that exceeds memory limits will be terminated
data = [0] * 10_000_000_000  # May trigger ResourceError

Execution Time Limits

# Infinite loops are caught by timeout
while True:
    pass  # Will be terminated after time limit

Allocation Limits

# Excessive allocations trigger limits
for i in range(1_000_000):
    data = [0] * 1000  # May trigger ResourceError
Resource limits are configurable by the host and are designed to prevent runaway agent code from consuming excessive resources.

Import System Limitations

No Dynamic Imports

The __import__() function and importlib are not available.
# ❌ Dynamic imports don't work
module = __import__('sys')

import importlib
mod = importlib.import_module('os')

No Import Hooks

Custom import hooks and meta path finders are not supported.
# ❌ These don't work
import sys
sys.meta_path.append(custom_finder)

Advanced Python Features

These advanced features are not supported:

No Metaclasses

Since classes aren’t supported yet, metaclasses are also unavailable.

No Decorators on Classes

Class decorators don’t work (no classes), but function decorators work fine:
# ✅ Function decorators work
def my_decorator(func):
    def wrapper(*args, **kwargs):
        print('Before')
        result = func(*args, **kwargs)
        print('After')
        return result
    return wrapper

@my_decorator
def my_function():
    print('Function')

No Generators (Some Limitations)

Basic generators work, but some advanced features may not be fully supported:
# ✅ Simple generators work
def count(n):
    for i in range(n):
        yield i

for num in count(5):
    print(num)

No Context Managers (Limited)

The with statement has limited support. Custom context managers may not work fully.
# ⚠️ Limited support for context managers
# Simple cases may work, complex ones may not

What Monty IS Designed For

Despite these limitations, Monty excels at its intended use case:
Perfect for running LLM-generated Python code:
async def agent(prompt: str, messages: list):
    while True:
        output = await call_llm(prompt, messages)
        if isinstance(output, str):
            return output
        messages.extend(output)
Excellent for coordinating external function calls:
# Fetch data concurrently
import asyncio

user, prefs, history = await asyncio.gather(
    get_user(user_id),
    get_preferences(user_id),
    get_history(user_id)
)

return analyze(user, prefs, history)
Great for processing and transforming data:
def process_results(items: list) -> dict:
    filtered = [x for x in items if x['score'] > 0.8]
    grouped = {}
    for item in filtered:
        category = item['category']
        if category not in grouped:
            grouped[category] = []
        grouped[category].append(item)
    return grouped
Ideal for agent decision-making logic:
def decide_action(state: dict) -> str:
    if state['confidence'] < 0.5:
        return 'ask_clarification'
    elif state['data_missing']:
        return 'fetch_more_data'
    else:
        return 'process_response'

Comparing to Alternatives

Why use Monty despite these limitations?
FeatureMontyDockerPyodideFull Python
Startup time<1μs~195ms~2800ms~30ms
SecurityStrict sandboxGood isolationPoorNone
StdlibLimitedFullFullFull
Third-party libsNoYesMostYes
ClassesComing soonYesYesYes
Use caseAgent codeGeneralBrowserGeneral
When to use Monty:
  • Running LLM-generated code
  • Need microsecond startup times
  • Security is critical
  • Stdlib subset is sufficient
  • Building agentic systems
When NOT to use Monty:
  • Need full Python compatibility
  • Require third-party libraries
  • Need classes today (coming soon)
  • General-purpose scripting

Roadmap

Planned improvements:
  1. Class support - Coming soon
  2. Match statements - Coming soon
  3. More stdlib modules - datetime, dataclasses, json
  4. Enhanced async features - Better asyncio integration
Follow development on GitHub and join the Pydantic Slack for updates.

Next Steps

Python Subset

See what Python features ARE supported

Standard Library

Explore available stdlib modules

Build docs developers (and LLMs) love