Magic Widget
Android home-screen widgets that are MicroPython scripts, run in a sandbox embedded through the NDK.
MicroPython (C, built with the NDK's clang)JNIKotlinhome-screen widget
The product
Each home-screen widget in Magic Widget is a small MicroPython script. I embedded the interpreter in the app through the NDK and JNI and built a sandbox around it, so a script can fetch data, draw a card and react to taps without being able to hang the phone.
Widgets are written by an LLM pipeline from a plain request: a small model plans, a stronger one writes, then static checks, a sandboxed dry run and deterministic checks on the rendered card decide whether it ships, with at most three attempts.
Under the hood
THE ENGINEERING
- 01
MicroPython's embed port compiled for each shipped ABI with the NDK's clang by my own build script
- 02
A pthread watchdog per run: a 500 ms CPU budget read from the VM thread's own CPU clock and a 10 s wall-clock cap, so a script waiting on the network spends wall time, not CPU budget
- 03
One interpreter at a time behind a lock, a single native bridge function and a 4 MB heap
- 04
Script http module with caching, ETag revalidation, the last good response when offline, and per-widget rate and size caps
- 05
Provider API keys encrypted with AES-GCM under a non-exportable Android Keystore key
- 06
681 JVM tests (Robolectric) plus golden-image tests on an Android emulator; text contrast checked against WCAG AA by a unit test in both themes
Next case study
PicoAndroid IDE →