Skip to main content

modebox for Python

Run untrusted, agent-written JavaScript and TypeScript in a WebAssembly sandbox whose only authority is the functions you give it. When a call needs approval, the whole VM is sealed into an encrypted token; the run resumes later, even in another process, and nothing runs twice.

This is the Python API for modebox. It matches the modebox npm package. Python 3.10 or later on macOS (arm64, x64) or Linux (x64, arm64, glibc).

pip install modebox

Each of those platforms gets a prebuilt wheel. Anywhere else, pip builds from the source distribution, which needs Rust 1.96 or later.

Usage

import modebox

async def get_weather(city: str) -> dict:
    return {"city": city, "temp": 18}

@modebox.require_approval
async def send_email(to: str, body: str) -> str:
    ...
    return "sent"

host_functions = {"weather": {"get": get_weather}, "email": {"send": send_email}}

runner = modebox.Runner(limits=modebox.Limits(timeout_ms=5_000))
result = await runner.run(
    "const w = await weather.get('Paris'); await email.send('me@example.com', `${w.temp}°C`); w.temp",
    host_functions=host_functions,
)
if result.status == "interrupted":  # paused before email.send; nothing has been sent
    result = await runner.run(
        host_functions=host_functions,
        continuation=result.continuation,  # a token you can store and resume in another process
        resolutions=[modebox.approve(result.interruptions[0].id)],
    )
print(result.value, result.logs, result.stats)
  • modebox.run(...) uses a shared default Runner; run_sync(...) runs without an event loop.
  • Host functions can be plain functions or async def. They run on your event loop.
  • Inside a host function, modebox.get_host_function_context() gives the call's details, and .interrupt(payload) pauses the run. Resume with modebox.resume_with(id, value), and the host function runs again with ctx.resume.resolution == value.
  • approve=["bank.*"] needs approval for matching calls. sources and sinks make every sink call after a source call wait for approval.
  • Failures raise modebox.RunError with kind and code, or return status="failed" with throw_on_error=False.
  • runner.declarations(host_functions, schemas) gives TypeScript declarations for the model's prompt.

Values

JavaScript Python
null, undefined None (send modebox.UNDEFINED for undefined)
number int when whole, else float (NaN, ±Infinity and -0 kept)
BigInt int (ints beyond ±2⁵³ cross as BigInt)
string, boolean, array, object str, bool, list (or tuple), dict
Map, Set modebox.JsMap (a dict), set
Date datetime in UTC (naive datetimes are taken as UTC)
Uint8Array, ArrayBuffer bytes (other typed arrays: array.array)
RegExp, Error modebox.JsRegExp, modebox.JsError

Dataclasses cross as objects. Functions and other objects can't cross; returning one from a host function is an error in the sandbox.

See the main README for the security model and limitations.

Metadata

Release files for modebox 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modebox 0.2.0
File Size Uploaded Provenance
modebox-0.2.0.tar.gz 760.5 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for modebox 0.2.0
File
modebox-0.2.0-cp310-abi3-manylinux_2_34_x86_64.whl CPython 3.10 abi3 Linux glibc 2.34+ x86-64 Details
modebox-0.2.0-cp310-abi3-manylinux_2_34_aarch64.whl CPython 3.10 abi3 Linux glibc 2.34+ ARM64 Details
modebox-0.2.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
modebox-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 41.6 MB

Release files / modebox-0.2.0.tar.gz

Download URL modebox-0.2.0.tar.gz
Size 760.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dd0ce02cad8b1e91c10b7daf28419cb99f53c7bde46c89771f633ccf25ad6030
BLAKE2b-256 checksum
How to use checksums
c558b125aa429faaa5fc2661af0eb37a7eeebba813bc3fd160a6930e891aaa96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / modebox-0.2.0-cp310-abi3-manylinux_2_34_x86_64.whl

Download URL modebox-0.2.0-cp310-abi3-manylinux_2_34_x86_64.whl
Size 10.9 MB
Tags CPython 3.10 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
37f78fbdef5e26b7c8d299c871da9f9db7b6d7edeaaf60092d6b7573a52ef760
BLAKE2b-256 checksum
How to use checksums
be4715bb4fb70b0b3738d1b2a0fc1eb1c3c61f4b6554168fff4229baa7d16537
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / modebox-0.2.0-cp310-abi3-manylinux_2_34_aarch64.whl

Download URL modebox-0.2.0-cp310-abi3-manylinux_2_34_aarch64.whl
Size 10.3 MB
Tags CPython 3.10 Linux glibc 2.34+ ARM64 abi3
SHA-256 checksum
How to use checksums
041d0709fe8c4d82e39b6083a3a08eaabee85ec5819434f75b806e1c83f847ec
BLAKE2b-256 checksum
How to use checksums
9bdf311223c4a3239e067f5af0294c0474e6ef1b356ca80e4436b6bdfe1cb331
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / modebox-0.2.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL modebox-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Size 9.3 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5a1c719cc50dee4e35d5e96fcff9817980771171df837613ffa410863485e977
BLAKE2b-256 checksum
How to use checksums
1776aafd15243d01ca6a6647b099211616af6e1d2fb8bce87eeeb4ac6dc1fb35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / modebox-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL modebox-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 10.3 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
be5fb1d0bbf083af79b5bea337d528b5153378de21a2bef4ae97f59b0538553e
BLAKE2b-256 checksum
How to use checksums
e67d18801bc424d75b2246ee4ef779f5dc8e908042fc20859eb9e9827df9ddcc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for modebox 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for modebox-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page