# Simon Willison Ships micropython-wasm 0.1a2 — Runs Untrusted Python Inside a WASI MicroPython Sandbox With wasmtime Memory Caps, CPU 'Fuel' Limits, and Persistent Sessions for LLM Agent Tool Use

> A WASI MicroPython sandbox so LLM agents can run untrusted Python with hard memory and CPU limits.

- Org: Simon Willison
- Date: 2026-06-06
- Category: article, tool
- Source: https://simonwillison.net/2026/Jun/6/micropython-in-a-sandbox/
- Canonical page: https://ai-tldr.dev/releases/simonwillison-micropython-wasm-sandbox/

## In short

Willison ships an alpha Python library that compiles MicroPython to a 362KB WASI WebAssembly blob, runs it via wasmtime, and exposes a persistent interpreter to host code with hard memory caps and a CPU 'fuel' budget for safe LLM tool-call execution.

## What it is

An alpha Python package, micropython-wasm 0.1a2, that ships MicroPython compiled to a WASI WebAssembly module and drives it from CPython via wasmtime. It exposes a CLI plus a long-lived sandboxed interpreter you can feed code into from your own application.

## How it works

78 lines of C glue compile alongside MicroPython into a 362KB WASM blob. A wasmtime host runs the module with persistent interpreter state across calls (via threading and a message queue), enforces memory limits directly through the WebAssembly engine, and caps CPU work using wasmtime's 'fuel' mechanism. The companion datasette-agent-micropython plugin wires this sandbox into Datasette Agent as a tool an LLM can call.

## Why it matters

Plugin systems for Datasette, LLM, and most agent harnesses today execute Python with full host privileges, so any code the model writes can read the filesystem or hit the network. A WASM-bounded MicroPython interpreter is small enough to embed and strict enough to constrain memory and CPU, giving agent authors a credible sandbox for model-written code without spinning up a container.

## Who it's for

Authors of Python LLM agents and plugin systems who need a code-execution tool that does not trust the model.

## Try it

uvx micropython-wasm -c 'print("Hello world")'

## Links

- [Blog Post](https://simonwillison.net/2026/Jun/6/micropython-in-a-sandbox/)
- [GitHub Repo](https://github.com/simonw/micropython-wasm)
- [PyPI Package](https://pypi.org/project/micropython-wasm/)
- [Release 0.1a2](https://github.com/simonw/micropython-wasm/releases/tag/0.1a2)
