5 ms·
OK this looks promising: brew install wasmer wasmer run python/python@=0.2.0 Running that gave me a Python 3.12 shell apparently running entirely in a Web
by simonw 1y ago
OK this looks promising:
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.
- theanonymousone 1y agoHasn't Pyodide been available for some years now?
- simonw 1y agoYes but it works only in the browser - running Pyodide outside of a browser is a lot of extra work. My previous attempts are described here: - https://til.simonwillison.net/deno/pyodide-sandbox https://til.simonwillison.net/deno/pyodide-sandbox - https://til.simonwillison.net/webassembly/python-in-a-wasm-sandbox https://til.simonwillison.net/webassembly/python-in-a-wasm-s...
- almostgotcaught 1y agonot true 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-from-source.html#testing-packages-against-pyodide https://pyodide.org/en/stable/development/building-packages-...
- simonw 1y agoInteresting - I hadn't seen that before: > 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?
- almostgotcaught 1y agoNo clue - I added that CI job around 6 months ago.
- simonw 1y agoI tracked it down to this PR from September 2022, so it's been around for a while: https://github.com/pyodide/pyodide/pull/2976 https://github.com/pyodide/pyodide/pull/2976
- ZhiqiangWang 1y agoWhat is the point of running python in webassembly outside browser?
- simonw 1y agoSee comment here: https://news.ycombinator.com/item?id=45365165 https://news.ycombinator.com/item?id=45365165 I want a robust sandbox I can run untrusted code in, outside of the browser.
- syrusakbary 1y agoThanks! 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
- klas_segeljakt 1y agoI tried to run these commands. It downloads python@3.13.1, but then hangs without producing any output. However, it seems to work for wasmer run python/python@=0.2.0
- deleted 1y ago[deleted]
- behnamoh 1y ago``` ╰─ wasmer run python/python error: Spawn failed ╰─▶ 1: compile error: Validate("exceptions proposal not enabled (at offset 0x191a)") ```
- the_duke 1y agoYou'll need the latest wasmer RC for proper exceptions support. 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
- simonw 1y agoHow long should it take for "wasmer run python/python" to start showing me output? It's been hung for a while for me now (I upgraded to wasmer 6.1.0-rc.5). "wasmer run python/python@=0.2.0" on the same machine gets me into Python 3.12.0 almost instantly.
- the_duke 1y agoCompilation with LLVM takes quite a while (the final release will show a spinner...). So please wait a bit - subsequent runs will be fast, since compiled Python will be cached.
- simonw 1y agoOh so it's actually compiling everything on my machine? Any chance `wasmer run python/python` might download a pre-compiled version in the future?
- the_duke 1y agoYeah, that's mentioned as a small side note in the blog post - we are working on it, and will hopefully have it ready in a week or two!
- 1y ago
- giancarlostoro 1y agoEveryday we grow closer to my dream of having a WASM based template engine for Python, similar to how Blazor takes Razor and builds it to WASM. I might have to toy with this when I get home.
- BiteCode_dev 1y agoIdeally, something that we could share between JS and Python.
- mr_toad 1y ago> 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. reply What’s the use case? Is it the sandboxing? Is it easier than running Python in a container?
- NeutralForest 1y agoThe sandboxing, especially for AI Agents.
- simonw 1y agoI want to be able to run code from untrusted sources (other people, users of my SaaS application, LLMs) in an environment, where I can control the blast radius if something goes wrong.
- BeefySwain 1y agoWhat's wrong with Docker for this?
- hmmokidk 1y agoDocker would be hacky and cumbersome especially when compared to anything assembly like.
- simonw 1y agoI keep on hearing that Docker isn't designed as a security boundary for this kind of thing. Firecracker is meant to be secure but it's a lot harder to work with.
- phrotoma 1y agoHey Simon, given it's you ... are you concerned about LLMs attempting to escape from within the confines of a Docker container or is this more about mitigating things like supply chain attacks?
- trehans 1y agoDoes this work for packages with C/C++ extensions e.g. numpy and scipy?
- ashvardanian 1y agoSeems like it already does for some, assuming Pillow and FFMpeg are on the list.
- zebreus 1y agoBuilding packages with C/C++ extensions is still a bit tricky but you can see a list of all prebuilt packages for wasmer at https://pythonindex.wasix.org https://pythonindex.wasix.org . numpy is available there, scipy not (yet).
- Art9681 1y agoBummer. Back to Docker then.
- gvkhna 1y agoWow, this is the key. If it just had python that’s not as useful but the major frameworks is the real value. Definitely going to keep an eye on this. I built a sandbox with deno for ai code generation. It works well enough but there are some use cases where python may make more sense. Nice!
- indigodaddy 1y agoAny chance your deno thing is on GH?
- gvkhna 1y agoYup, github.com/gvkhna/vibescraper in the sandbox package. Def needs a cleanup but it’s heavily tested and works great at aivibescraper.com