Skip to main content
Pydantic Monty runs python3 in both SDKs, including Node and browsers. It supports a subset of Python and works with workspace files under the same permissions as shell commands. Programs cannot access host files, host environment variables or the network.

Installation

Usage

Declare a worker machine to run python3 on Monty, in worker processes Mirage starts:

Memory

Set max_memory to limit the Python program’s memory per run, using a size such as 64M:
A run that needs more raises MemoryError. A run also holds no more than its workspace’s max_memory has left, 96 MB by default.

Python compatibility

Support applies to both SDKs unless a row says otherwise. For Python syntax and standard-library coverage, see Monty’s limitations. Examples assume a writable /data mount. Mount modes and permissions still apply.

open()

Modes and modifiers are listed separately; for example, rb combines r and b.

File objects

os

The working directory and environment come from the Mirage session, not the host.

File operations

Directory operations

Environment and working directory

os.path

pathlib

Path.cwd() and relative path resolution use the shell’s working directory.

sys

Mirage passes command inputs through the runtime globals.

time and datetime

The clocks start at the workspace’s system time when it sets one, and files the program writes are stamped from the same clock. time.monotonic() and time.perf_counter() measure elapsed time.

json

JSON parsing and serialization come from Monty; see its json reference.

csv, tomllib and hashlib

These modules read and write workspace files through open().

Runtime globals

  • argv: The invocation name and arguments.
  • stdin: The piped input.
  • __file__: The script’s name under the starting directory.

Notes

  • A run starts in the shell’s working directory. The script and every relative path pass the same mount and permission checks as cat: a rule protecting /data/job.py refuses python3 job.py from /data.
  • Script arguments follow shell expansion, including globs.
  • A console session takes the working directory on its first input and keeps its own after that.
  • raise SystemExit exits successfully. raise SystemExit("message") exits with status 1 and prints the message.

Python subset

Monty 1.4.0 implements a subset of Python, and Mirage never falls back to another interpreter. Monty maintains the details of its standard-library modules and language limitations. Those pages track upstream Monty; the integration tables above describe the version used by Mirage. Third-party imports are unavailable.

Unsupported modules

Common modules unavailable in Monty 1.4.0:
  • Files: glob, io, shutil, tempfile.
  • Networking: http, socket, ssl, urllib.
  • Processes and concurrency: concurrent.futures, multiprocessing, queue, subprocess, threading.
  • Data formats and archives: array, pickle, struct, zipfile, zlib.
  • Numbers and hashing: fractions, hmac, uuid.
  • Language and introspection: abc, contextlib, ctypes, importlib, inspect, types, weakref.
  • CLI and diagnostics: argparse, logging, traceback, unittest, warnings.
  • Other utilities: enum, heapq, operator, string.