Running Python code in a sandbox with MicroPython and WASM

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Python developers who need to run untrusted code safely now have a dependency-free WASM-based sandbox installable directly from PyPI.

Read this as

Programmer Simon Willison released an alpha tool called micropython-wasm that runs Python code inside a sealed box, so the code cannot snoop on files, use the network, or crash the host computer. It works by running a miniature version of Python, called MicroPython, inside WebAssembly, a security technology web browsers use to run downloaded code safely. The tool is live on PyPI and is already used by his Datasette Agent.

Simon Willison released micropython-wasm, an alpha Python package on PyPI that executes untrusted code in a WebAssembly sandbox using MicroPython. Its 362KB WASM blob installs cleanly from PyPI with no extra steps, with memory limits via wasmtime and a 20 million 'fuel' cap on CPU operations. Practical use today is mostly within Willison's own Datasette Agent project; the package is explicitly an alpha, and the CPU limit value is unproven.

micropython-wasm compiles MicroPython to a 362KB WebAssembly binary run via the wasmtime Python library, built from Yamamoto Takahashi's experimental WASI support PR. Persistent sessions block the interpreter on a host function feeding code to eval(), queue-based, with host functions exposed via 78 lines of compiled C. Memory limits come from wasmtime; CPU limits use a fuel setting of 20 million, which the author flags as untested. It powers the datasette-agent-micropython plugin.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

micropython-wasm MicroPython WebAssembly wasmtime Datasette Agent Pyodide PyPI

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading