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.1.1

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.1.1
File Size Uploaded
modebox-0.1.1.tar.gz 761.9 kB Details

Built distributions (wheels)

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

Total release size: 41.5 MB

Release files / modebox-0.1.1.tar.gz

Download URL modebox-0.1.1.tar.gz
Size 761.9 kB
Tags Source
SHA-256 checksum
How to use checksums
f0c800d487b76784f3e1437249e974a44c81fb9f8874696026b3b8259388ad8c
BLAKE2b-256 checksum
How to use checksums
13111352fcb791c83078fc024146a209cd83a9d56cfe17d017350ae4f5da03c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 13, 2026.

Transparency log

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

Download URL modebox-0.1.1-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
e46a886ed94b96c2153f90979f93913aad07e08f1b6cd48ff9a7eca791e7b989
BLAKE2b-256 checksum
How to use checksums
fd578e1500aaf9275a8c0ca3ec7f4c1822c0fe1914d7f01bec7663fdf1cff5a1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 13, 2026.

Transparency log

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

Download URL modebox-0.1.1-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
d6fb695343a98318202aa05391cd3c87ec5a6221641a33e284f4a18dbd2bbc32
BLAKE2b-256 checksum
How to use checksums
3bb60bb6fc4e03ed57a419dc3dc1ed94368646ff5f66aaac62a2fdbe047cf93b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 13, 2026.

Transparency log

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

Download URL modebox-0.1.1-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
6f259bd110d8a4afa7783e78177fc3d7e9d98b246c540e8766842e059de4dd60
BLAKE2b-256 checksum
How to use checksums
5a8f095808550c096258260899dd2692214293a98b65d026f4b8bdd02a98bd82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 13, 2026.

Transparency log

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

Download URL modebox-0.1.1-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
49a4acd0b78e51bb358799208a22578981f909426809ae30df1ba6230ec06490
BLAKE2b-256 checksum
How to use checksums
3256bd1d504c09f3f47c396c4f0c6f91256da75bc8aea90c0df63d8a760f498c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 13, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

5 release files

This release

0.1.1 This release

5 release files

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