A sandboxed Python subset. Classes, async/await, structural pattern matching, and packages.json imports.
Compiled to bytecode. Run on a stack VM with adaptive inline caching and pure-function memoisation. See Design for internals.
It reads like Python: it parses Python syntax. It runs differently. What it executes is curated.
What it supports
- First-class functions: pass them, return them, store them in lists and dicts. Decorators apply to both
defandclass. - Lambdas with closures: full lexical capture via shared cells, so sibling closures and
nonlocalwrites see each other; currying, partial application. - Generators and coroutines:
yield,yield from,async def,await. Generator expressions are eagerly materialised to lists; use adefwithyieldfor true laziness. - Comprehensions: list, dict, and set, with multiple
forclauses andifguards. - Pattern matching:
match/casewith literals, captures, OR-patterns, guards, and sequence patterns (one star permitted). - Exceptions:
try/except/else/finally, named handlers,raise X from Y(chain info discarded butXis what propagates), and subclass-aware matching (except ExceptioncatchesRuntimeError). - Context managers:
withandasync withinvoke__enter__/__exit__on the context-manager value; a truthy return from__exit__suppresses the raised exception. - Protocol dunders: operator overloading, indexing, iteration, hashing, and
repr/str/formatdispatch through user-defined dunders; see Dunders for the full matrix. - Numbers: bounded integers (fast inline path, auto-promoting to wide; see Integer width) and full IEEE-754 floats. No
complex,Decimal, orFraction. - Sequences: lists, tuples, dicts (insertion-ordered), sets, frozensets, ranges, strings (UTF-8, codepoint-indexed), and bytes.
- f-strings: full grammar, embedded expressions,
{expr=}self-doc,!r/!s/!aconversions, and format specs coverings d b o x X f F e E g G n % cplus fill / align / sign /#/0/ width /,/ precision. - Walrus operator:
:=in expressions (Name target only). - Type annotations: parsed and discarded, no runtime
__annotations__, no enforcement. - Module identity:
__name__is bound to"__main__"in the entry chunk and to the module’s spec inside imported modules, so the canonicalif __name__ == "__main__":guard works as expected. - Modules:
import,from <spec> import names, andfrom <spec> import *resolve at parse time through a host-injected resolver, with optional#sha256-<hex>integrity on URL specs. Two flavors:.pysource modules and native modules. See Imports for resolution semantics, Writing modules for the three delivery paths, and Official packages for the ready-made modules (json,dom,network,storage, and more).
What it doesn’t support
These parse for syntactic compatibility. They raise at runtime, or don’t exist:
- Standard library: no bundled stdlib. Every module is external (see *Modules- above).
- I/O:
input()reads from a host-provided buffer. No file system, no network, noos, nosys. These surface only when the host runtime registers them as host capabilities, the same mechanism behindprintandinputthemselves. - Async surface:
async defcreates real coroutines, and the VM runs a cooperative scheduler. Noasynciomodule; the primitives are top-level builtins (Async). - Metaclasses, descriptor protocol,
__slots__: not modeled. - Dynamic code: no
exec, noeval, nocompile, no__import__(use theimport_module(name)builtin to look up an already-imported module by alias). - Reflection: nothing beyond
type,id,hash,repr,callable,getattr,hasattr,vars,globals,locals,isinstance, andissubclass.diris absent. - Relative imports:
from . import xis not supported; use quoted relative specs orpackages.jsonaliases (Imports).
Design philosophy
Multi-paradigm sandboxed compiler:
- Small binary, compiler + VM in one WebAssembly release.
- Faster interpreter, no method-resolution overhead; hot opcodes promote to type-specialised fast paths via IC.
- Aggressive memoisation, pure functions auto-cached after two hits (Functions); most functional code is pure by construction.
- Easier sandboxing, no protocol dispatch, no stdlib; attack surface is the fixed built-in set.
Sandbox guarantees
Inherits WASM-host guarantees: no syscalls, no FS, no network, isolated linear memory. On top, embedders enforce per-VM caps via Limits::sandbox(). Hits raise recoverable RuntimeError / MemoryError / RecursionError rather than crashing the host. See Limits and errors.
Where it runs
One .wasm artifact (compiler.wasm, a ~200 KB release) runs anywhere WebAssembly does:
- Browser: served alongside the
runtime/JS package, which bridgesprint()and module imports across theWASM <-> JSboundary. The host runtime owns I/O, fetching, and module loading. - Embedded Rust apps: load
compiler.wasmvia your runtime of choice or use thecompilerrlib when cargo-linked.
Two ABIs sit on top:
Compiler <-> hostimports, embedder-declared, covering output, module fetching, native dispatch, wall-clock time. Custom embedders that ship host capabilities declare additional imports (DOM, FS) without touching the plugin ABI.- Plugin ABI (sealed v1), contract for CDN-distributed
.wasmplugin modules. Exactly 6env.*imports, never extended. See the WASM module ABI.