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 defaultRunner;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 withmodebox.resume_with(id, value), and the host function runs again withctx.resume.resolution == value. approve=["bank.*"]needs approval for matching calls.sourcesandsinksmake every sink call after a source call wait for approval.- Failures raise
modebox.RunErrorwithkindandcode, or returnstatus="failed"withthrow_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.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| modebox-0.1.2.tar.gz | 757.7 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| modebox-0.1.2-cp310-abi3-manylinux_2_34_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.34+ x86-64 | Details |
| modebox-0.1.2-cp310-abi3-manylinux_2_34_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.34+ ARM64 | Details |
| modebox-0.1.2-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details |
| modebox-0.1.2-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.2.tar.gz
| Download URL | modebox-0.1.2.tar.gz |
|---|---|
| Size | 757.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
379dbf1458ee880ebcde40c9bfa670bd34753ed8a43a8972fca4e2739d6d2170
|
|
BLAKE2b-256 checksum How to use checksums |
28e09ca21277e5c9fd9c776b38eac317ab21c5c5a3b847656029c045b3ad134a
|
| 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 14, 2026.
Transparency logRelease files / modebox-0.1.2-cp310-abi3-manylinux_2_34_x86_64.whl
| Download URL | modebox-0.1.2-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 |
8e9f116c53457cb73d3aed5616a2cee5f4b1246201e2782b84e431bb68912f2b
|
|
BLAKE2b-256 checksum How to use checksums |
594e936b2ba38af698702d49e39cb0d0fa4db303a8ea1aa8ab046cfaeab2da25
|
| 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 14, 2026.
Transparency logRelease files / modebox-0.1.2-cp310-abi3-manylinux_2_34_aarch64.whl
| Download URL | modebox-0.1.2-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 |
ef62b27a0f1f6b08f863058f5a4781c224e089d3ff68e6faab956f0c366ab802
|
|
BLAKE2b-256 checksum How to use checksums |
f32aaa24e0bc525184fe6ce185640a03569b35fffab73ac092746abd81a7dcb6
|
| 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 14, 2026.
Transparency logRelease files / modebox-0.1.2-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | modebox-0.1.2-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 |
9ff902092175d21ae9d7c1cfe19a2e2a88e718d6171f0797643c025800a11459
|
|
BLAKE2b-256 checksum How to use checksums |
4e190be764099317d6d081403f1dd891af56078c038789edad42dbafab0eeec2
|
| 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 14, 2026.
Transparency logRelease files / modebox-0.1.2-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | modebox-0.1.2-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 |
04999ef729d78f0ef39a4651672d9c0a660fd80a3a9279d9fb50d75d338e7c26
|
|
BLAKE2b-256 checksum How to use checksums |
2b1be29209b55c3db0b57cf743be18cd35c632f983eeb1a81677ff324bc3ffb3
|
| 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 14, 2026.
Transparency log