by simonw · 1y ago · 0 comments
brew install wasmer
wasmer run python/python@=0.2.0
Running that gave me a Python 3.12 shell apparently running entirely in a WebAssembly sandbox!I've been trying to find a robust, reliable and easy way to run a Python process in WebAssembly (outside of a browser) for a few years.
Forgot to put it on the article, but the latest Python requires the Wasmer rc.5 to run! (the final release will be coming very soon)
curl https://get.wasmer.io -sSfL | sh -s "v6.1.0-rc.5"
wasmer run python/python wasmer run python/python@=0.2.0What’s the use case? Is it the sandboxing? Is it easier than running Python in a container?
Firecracker is meant to be secure but it's a lot harder to work with.
My previous attempts are described here:
- https://til.simonwillison.net/deno/pyodide-sandbox
- https://til.simonwillison.net/webassembly/python-in-a-wasm-s...
pyodide venv .venv-pyodide
source .venv-pyodide/bin/activate
I don't know what runtime it uses but I have tests in nightly CI that run exactly like this.see https://pyodide.org/en/stable/development/building-packages-...
> Pyodide provides an experimental command line runner for testing packages against Pyodide. Using it requires nodejs version 20 or newer.
Looks like it's a recent addition?
I want a robust sandbox I can run untrusted code in, outside of the browser.
error: Spawn failed
╰─▶ 1: compile error: Validate("exceptions proposal not enabled (at offset 0x191a)")
```
We unfortunately didn't get the final release out quite in time...
curl https://get.wasmer.io -sSfL | sh -s "v6.1.0-rc.5"
wasmer run python/python"wasmer run python/python@=0.2.0" on the same machine gets me into Python 3.12.0 almost instantly.
So please wait a bit - subsequent runs will be fast, since compiled Python will be cached.