Running Python code in a sandbox with MicroPython and WASM (simonwillison.net)

24 points by theanonymousone 3 hours ago

incognito124 11 minutes ago

If you're interested in not reinventing the sandbox for LLMs, consider Judge0: https://judge0.com/

I have absolutely no relation to the project except for the fact that I went to the same Uni as the creator.

era86 3 minutes ago

I'm using judge0 for a Leetcode-clone I'm working on. Never thought of using it in the context of LLMs, though.

tmaly an hour ago

I am trying to think of a use case for this.

I was thinking the client side WASM version would be useful as a platform for beginners to practice a subset of Python in.

I can't really think of any good WASI use cases.

roywiggins 2 minutes ago

The idea is to expose it as a tool to your LLM agent so it can run calculations on its own initiative.

theanonymousone 25 minutes ago

For me it is a tool I avail to an LLM so that it can provide correct answers to a certain category of questions, instead of hallucinating nonsense.

networked 37 minutes ago

Hey Simon, if you're reading this, you should check out https://github.com/dbohdan/starlark-python. It's my AI port of starlark/java to pure Python influenced by your work. theanonymousone might want to give it a look, too, since it's a kind of sandboxed Python.

The project was inspired by https://github.com/simonw/micro-javascript (a C-to-Python port of MicroQuickJS) and Simon Willison's quest for sandboxed Python. Not only that, but I used the Claude Code transcript Simon published to generate a playbook the porting agent then followed. I wrote up the port at https://dbohdan.com/starlark-python.

I considered whether to port MicroPython, PocketPy, or a Starlark implementation to Python. I ultimately stuck with Starlark because it was designed for untrusted code and had a conformance test suite. This looked about as optimized for agentic coding as a problem could get. While Starlark is more restrictive than MicroPython or PocketPy, I consider my needs for configuration and safe scripting currently satisfied (see #users in the README).

theanonymousone 3 hours ago

P.S. I was casually searching for "sandboxed Python" for an experiment I'm working on, and reached this article that was published "today". Very nice coincidence! Thanks.