How pydantic/monty works
Monty is a Rust-based Python sandbox exposed through Rust, Python, and JavaScript bindings, with a CLI and a protocol-driven worker suitable for local or WebSocket hosting. The README demonstrates the main workflow: a host checks out a session, submits code and inputs, services requested host functions, and receives results. The graph preserves the documented sandbox controls, mounts, snapshots, type checking, and telemetry as capabilities. Internal links are limited where excerpts or indexed references show ownership; other implementation details are not inferred from directory names.
Main entry points: worker.rs Protocol child · __init__.py Python API · run.rs Python interpreter · checkout.rs Worker pool
Components 24
Host interfaces
- Rust API
crates/monty/src/lib.rs - Python API
crates/monty-python/python/pydantic_monty/__init__.py - Python OS access
crates/monty-python/python/pydantic_monty/os_access.py - JavaScript API
crates/monty-js/ts/session.ts - CLI entry
crates/monty-runtime/src/main.rs - CLI execution
crates/monty-runtime/src/run.rs - Host functions
Sandbox execution
- Filesystem mounts
crates/monty-fs/src/overlay.rs - Type checking
crates/monty-type-checking/src/type_check.rs - Sandbox types
crates/monty-types/src/os.rs - Python interpreter
crates/monty/src/run.rs - Object heap
crates/monty/src/heap/mod.rs
Worker protocol
- Protocol child
crates/monty-proto/src/worker.rs - Wire encoding
crates/monty-proto/src/wire.rs - WASM runtime
crates/monty-wasm-runtime/src/lib.rs - JS worker host
crates/monty-js/ts/worker/host.ts - Worker dispatch
crates/monty-js/ts/worker/serve.ts - Browser worker entry
crates/monty-js/ts/worker/browserWorkerEntry.ts - Node worker entry
crates/monty-js/ts/worker/nodeWorkerEntry.ts
Host operations
- Worker pool
crates/monty-pool/src/checkout.rs - Worker transports
crates/monty-pool/src/worker.rs - Pool telemetry
crates/monty-pool/src/telemetry/mod.rs
Other components
- Host application
- WebSocket host
Connections 24
- Host application → Python API: submits code
README.md - Host application → Rust API: runs sandbox
README.md - Host application → JavaScript API: runs sandbox
README.md - Host application → CLI entry: runs code
README.md - Python API → Worker pool: checks out
- Python API → Python OS access: handles OS access
crates/monty-python/python/pydantic_monty/os_access.py - CLI entry → CLI execution: starts execution
crates/monty-runtime/src/main.rs - Worker pool → Worker transports: drives worker
crates/monty-pool/src/worker.rs - Worker pool → Pool telemetry: records activity
crates/monty-pool/src/telemetry/mod.rs - Worker transports → Protocol child: exchanges requests
crates/monty-pool/src/worker.rs - Protocol child → Wire encoding: decodes messages
crates/monty-proto/src/worker.rs - Protocol child → Python interpreter: drives session
crates/monty-proto/src/worker.rs - Protocol child → Type checking: runs type checks
crates/monty-proto/src/worker.rs - Python interpreter → Object heap: stores objects
- Python interpreter → Filesystem mounts: uses mounts
- Python interpreter → Sandbox types: uses sandbox types
- Protocol child → WASM runtime: serves WASM worker
crates/monty-proto/src/worker.rs - JavaScript API → JS worker host: uses worker host
- Browser worker entry → Worker dispatch: starts dispatch
crates/monty-js/ts/worker/browserWorkerEntry.ts - Node worker entry → Worker dispatch: starts dispatch
crates/monty-js/ts/worker/nodeWorkerEntry.ts - Worker dispatch → JS worker host: serves requests
crates/monty-js/ts/worker/nodeWorkerEntry.ts - Host application → Host functions: provides callbacks
README.md - Python API → Host functions: services calls
README.md - WebSocket host → Worker transports: connects remotely
README.md