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

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.3
File Size Uploaded Provenance
modebox-0.1.3.tar.gz 757.8 kB With provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for modebox 0.1.3
File
modebox-0.1.3-cp310-abi3-manylinux_2_34_x86_64.whl CPython 3.10 abi3 Linux glibc 2.34+ x86-64 Details
modebox-0.1.3-cp310-abi3-manylinux_2_34_aarch64.whl CPython 3.10 abi3 Linux glibc 2.34+ ARM64 Details
modebox-0.1.3-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
modebox-0.1.3-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.3.tar.gz

Download URL modebox-0.1.3.tar.gz
Size 757.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bd457d529c00d0c87f5ca7b650f36e9bb0323e9e42a756a5635f2eaaab4b644d
BLAKE2b-256 checksum
How to use checksums
e37d0f4bd9ca5bcf6c49aaeaf457a79d7ced53dc7998e3bf908fb6a375b1eb90
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 15, 2026.

Transparency log

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

Download URL modebox-0.1.3-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
caa5c44b661c66cb8f22f143ab19a5420a137900043e209569ec72ed6bbd4d53
BLAKE2b-256 checksum
How to use checksums
1593343c9f849188d00e7e49673475a944cd7d248a123db1cca487e271625f94
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 15, 2026.

Transparency log

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

Download URL modebox-0.1.3-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
4f290c4370d4fe14f68c1269bed935b880c4483b887bb2a48b9c2cb6e12c3023
BLAKE2b-256 checksum
How to use checksums
6d00096a7d2bba92a764c12460f4cc52d430b92d1d1092046cf7eaed8ca5b52d
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 15, 2026.

Transparency log

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

Download URL modebox-0.1.3-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
a6d21a47bfcec00f64ab6d3b53953a7580172fac6faa870ba9ee0bb6819eb2eb
BLAKE2b-256 checksum
How to use checksums
25cbb95c67402f9c2e87f8b32ae61a2c864452301a26c0c20e879fae9519e0e1
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 15, 2026.

Transparency log

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

Download URL modebox-0.1.3-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
a30e5fc5a974268ce52086f8372b017e004ca8b4805ca3baa37013ba0c41d476
BLAKE2b-256 checksum
How to use checksums
dd27c20115b75409d3f537188851c4dcdaccddf325e9869434211d250e71b3a0
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 15, 2026.

Transparency log

Security for modebox 0.1.3

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.1.3.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 15, 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