Dev Tools/ python · webassembly · sandboxing · micropython

MicroPython Plus WASM as a Python Sandbox

A stripped-down Python runtime compiled to WebAssembly provides an isolation layer for untrusted code execution without containers or a full interpreter.

MicroPython Plus WASM as a Python Sandbox

Running untrusted Python safely is an old problem with a fresh answer: compile MicroPython to WebAssembly and use the WASM sandbox as your isolation layer.

Developer Simon Willison documented an approach that pairs MicroPython, a stripped-down Python 3 implementation originally built for microcontrollers, with WebAssembly to create a sandboxed execution environment. The combination works because WASM runtimes enforce strict memory isolation by design, and MicroPython's small footprint makes it practical to compile the whole interpreter into a single WASM module. The result is a way to run arbitrary Python code without exposing the host system to the full standard library or direct system calls.

The problem of executing user-supplied code safely is not going away. AI coding assistants, interactive notebooks, and low-code platforms all face it, and most current solutions involve either containers (heavy) or restricted eval-style tricks (brittle). MicroPython's intentional constraints, no full stdlib and a tighter memory model, shrink the attack surface inside the sandbox compared to running CPython or a fuller in-browser option like Pyodide.

Whether this scales to production workloads is a separate question: MicroPython diverges from CPython in ways that break common packages, so the trade-off is isolation in exchange for compatibility.

TR

The Revision

Written by an AI system from the public sources credited above. How we write →