monty-types
Shared boundary types for Monty, the Python sandbox — the owned, heap-free data types that cross between the sandbox and the hosts that embed it, with no interpreter implementation.
What's here
MontyObject/MontyType— Python values and their types at the host boundary, including thedatetimefamily (MontyDate,MontyDateTime,MontyTimeDelta,MontyTimeZone) andMontyFileHandle.ObjectRef— a borrowed value, with typed accessors (as_int,as_str,items,pairs).MontyObject::as_ref()borrows a value for inspection.CallArgs/NamedValues— the arguments or inputs of one message. Their builders acceptMontyObjectvalues; their iterators return borrowed values. Both carriers and theMontyObject/ObjectReftypes keep their fields private.unstable— graph representation APIs for bindings and transport adapters, with no API compatibility guarantee. They may change or disappear in any release; prefer value constructors and typed accessors when possible.MontyException/ExcType— exceptions with tracebacks (StackFrame,CodeLoc) and structured payloads (ExcData).OsFunctionCall— the typed OS-call payloads sandboxed code suspends with (file reads/writes,open(),os.getenv, ...), plus thestat_resultbuilders hosts use to answer them.MontyPathpreserves OS-call paths for validation;normalize_virtual_pathprovides the lexical POSIX normalization shared by the interpreter, mounts, andOsFunctionCall::to_args()callbacks. It borrows canonical paths and resolves relative inputs from/. Validate NUL bytes and path limits before calling it; it does not confine filesystem access.ResourceTracker/ResourceLimits— the resource tracker the interpreter uses to enforce time/memory/recursion limits, plus themax_suspensionsbudget hosts enforce themselves.PrintStream/PrintWriter/CollectedStreams—print()output capture, and the labelled buffer behindPrintWriter::CollectStreams.CompileOptions,ExtFunctionResult,NameLookupResult,FileMode, and the CPython-compatible formatting helpers behind theirrepr()s.
Who should depend on it
The monty interpreter enables the cpu-clock feature for native CPU accounting, which is Linux-only.
Host-only users do not need this feature or its platform CPU dependencies.
ExecutionClock::is_available() reports whether the current thread can read the selected clock.
Host-side crates that need these types without linking the interpreter —
monty-fs (which services OsFunctionCalls locally via
MountTable::handle_os_call), monty-pool (which talks to Monty workers
over the wire), the pydantic-monty-client Python bindings and the
@pydantic/monty JS bindings — depend on this crate instead of monty,
so their binaries never link the interpreter itself. Only worker-side crates
(monty-runtime, monty-wasm-runtime, and monty-proto with its worker
feature) link monty.
use MontyObject;
let value = list;
assert_eq!;
Monty crates
monty— the core interpreter: Python parser, bytecode VM, and sandbox.monty-types— the shared boundary data types (values, exceptions, OS calls, resource limits) hosts use without linking the interpreter. this cratemonty-fs— host-side filesystem mounts: maps virtual sandbox paths to real host directories.monty-runtime— themontybinary: REPL, file runner, and subprocess worker mode.monty-pool— an elastic pool of crash-isolatedmontyworker subprocesses.monty-proto— the protobuf wire protocol spoken between pool parents and workers.monty-type-checking— type checking of sandboxed code, powered by ty.monty-typeshed— the trimmed typeshed stubs describing the stdlib subset Monty implements.monty-macros— the proc macros behindmonty's argument parsing.
Execution time
Execution budgets charge bytecode and native builtins, excluding host suspension.
They use ExecutionClock::Wall by default. Native callers can select
ExecutionClock::Cpu with ResourceTracker::with_execution_clock.
Subprocess hosts set PoolConfig::execution_clock once for the pool; CPU enforcement needs a local Linux subprocess
worker, so remote (gRPC) setups enable it in the server's local pool. CPU mode samples the executing
thread with a cache of up to 1 ms and reads exact execution boundaries.
Unavailable or unusable counters use conservative elapsed time for that window; off Linux the counter is always
unavailable, so check ExecutionClock::is_available() before selecting CPU mode directly.
The OS controls counter accuracy and resolution. Snapshots preserve clock selection
and recorded consumption. WebAssembly workers accept wall mode only.
License
MIT