{"id":7554,"library":"pydantic-monty","title":"Pydantic-Monty","description":"Pydantic-Monty provides Python bindings for the Monty sandboxed Python interpreter, a Rust-based virtual machine designed for securely executing untrusted Python code. It is currently at version 0.0.12 and sees frequent, rapid releases as it is under active development, indicating ongoing feature additions and potential API changes.","status":"active","version":"0.0.12","language":"en","source_language":"en","source_url":"https://github.com/pydantic/monty","tags":["sandbox","virtual machine","security","rust","python bindings"],"install":[{"cmd":"pip install pydantic-monty","lang":"bash","label":"Install pydantic-monty"}],"dependencies":[],"imports":[{"symbol":"Monty","correct":"from monty import Monty"},{"symbol":"VmException","correct":"from monty import VmException"}],"quickstart":{"code":"from monty import Monty, VmException\n\n# Initialize the Monty VM\nvm = Monty()\n\n# Run some simple Python code inside the VM\nresult = vm.run('x = 10\\ny = 20\\nprint(x + y)')\nprint(f'stdout: {result.stdout.strip()!r}')\nprint(f'stderr: {result.stderr.strip()!r}')\nprint(f'return_value: {result.return_value!r}')\n\n# Example of handling a VM-level exception\ntry:\n    vm.run('raise ValueError(\"Something went wrong in the sandbox!\")')\nexcept VmException as e:\n    print(f'VM error caught: {e}')\n","lang":"python","description":"This quickstart demonstrates how to initialize the Monty VM, execute Python code within its sandboxed environment, and handle exceptions raised by the VM."},"warnings":[{"fix":"Review Monty's documentation for available built-ins and how to securely expose specific host resources like file paths via `vm.mount()` if necessary. Do not expect full standard library functionality without explicit configuration.","message":"Monty's VM is a sandboxed environment, meaning it has restricted access to many standard Python modules (e.g., `os`, `sys`, networking) and system resources by default. Code running within Monty cannot access the host filesystem or network unless explicitly configured (e.g., via `mount`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure all iterables passed to `zip()` within Monty's VM have the same length. If different lengths are expected, manually handle the shorter iterable's termination or implement custom zipping logic.","message":"As of v0.0.12, the `zip()` built-in function in Monty enforces strict mode, raising a `ValueError` if iterables passed to it have different lengths. This differs from standard Python 3's `zip()`, which truncates to the shortest iterable.","severity":"gotcha","affected_versions":">=0.0.12"},{"fix":"Pin your `pydantic-monty` dependency to an exact version (e.g., `pydantic-monty==0.0.12`) and review release notes carefully when upgrading to newer versions to identify potential breaking changes.","message":"The library is in early development (`0.0.x` versioning), which means APIs are subject to change without strict adherence to semantic versioning. Breaking changes may occur in minor or patch releases.","severity":"breaking","affected_versions":"All `0.0.x` versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that the module you are trying to import is either a Monty built-in or has been explicitly allowed/provided through VM configuration. Remember that Monty is a restricted environment.","cause":"Attempting to import a Python module (e.g., 'requests', 'numpy', or many standard library modules like 'os', 'sys') that is not allowed or built-in within the Monty sandboxed environment.","error":"ModuleNotFoundError: No module named 'requests'"},{"fix":"Ensure that the first argument to `vm.mount('host_path', 'vm_path')` points to an existing and accessible directory on the host machine before attempting to mount it.","cause":"Trying to mount a host directory into the Monty VM using `vm.mount()` where the specified host directory path does not exist on the underlying file system.","error":"VmException: ValueError('Cannot mount: directory does not exist: /path/to/non_existent_dir')"},{"fix":"Refactor the Python code running in the VM to avoid excessive recursion. If deeply recursive algorithms are intentional, review Monty's documentation for any configuration options to adjust the recursion limit (if available and safe to do so).","cause":"Code executed inside the Monty VM exceeded the configured recursion depth limit, typically due to an infinite recursion or deeply nested function calls.","error":"VmException: RecursionError: maximum recursion depth exceeded"}]}