Remix.run Logo
simonw 9 hours 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.

syrusakbary 8 hours ago | parent | next [-]

Thanks!

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
mr_toad 5 hours ago | parent | prev | next [-]

> 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?

simonw 5 hours ago | parent | next [-]

I 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.

NeutralForest 5 hours ago | parent | prev [-]

The sandboxing, especially for AI Agents.

giancarlostoro 7 hours ago | parent | prev | next [-]

Everyday 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.

trehans 4 hours ago | parent | prev | next [-]

Does this work for packages with C/C++ extensions e.g. numpy and scipy?

zebreus 6 minutes ago | parent | next [-]

Building 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 . numpy is available there, scipy not (yet).

ashvardanian 4 hours ago | parent | prev [-]

Seems like it already does for some, assuming Pillow and FFMpeg are on the list.

theanonymousone 9 hours ago | parent | prev | next [-]

Hasn't Pyodide been available for some years now?

simonw 8 hours ago | parent [-]

Yes 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/webassembly/python-in-a-wasm-s...

ZhiqiangWang 4 hours ago | parent | next [-]

What is the point of running python in webassembly outside browser?

simonw 3 hours ago | parent [-]

See comment here: https://news.ycombinator.com/item?id=45365165

I want a robust sandbox I can run untrusted code in, outside of the browser.

almostgotcaught 8 hours ago | parent | prev [-]

not 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-...

simonw 8 hours ago | parent [-]

Interesting - 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 8 hours ago | parent [-]

No clue - I added that CI job around 6 months ago.

simonw 8 hours ago | parent [-]

I tracked it down to this PR from September 2022, so it's been around for a while: https://github.com/pyodide/pyodide/pull/2976

8 hours ago | parent | prev | next [-]
[deleted]
behnamoh 7 hours ago | parent | prev [-]

``` ╰─ wasmer run python/python

error: Spawn failed

╰─▶ 1: compile error: Validate("exceptions proposal not enabled (at offset 0x191a)")

```

the_duke 7 hours ago | parent [-]

You'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 7 hours ago | parent [-]

How 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 7 hours ago | parent [-]

Compilation 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 7 hours ago | parent [-]

Oh 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 7 hours ago | parent [-]

Yeah, 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!

simonw 7 hours ago | parent [-]

OK got there in the end! I didn't time it but felt like around 10 minutes or more.

It did give me one warning message:

  % wasmer run python/python
  Python 3.13.0rc2 (heads/feat/dl-dirty:152184da8f, Aug 28 2025, 23:40:30) [Clang 21.1.0-rc2 (git@github.com:wasix-org/llvm-project.git 70df5e11515124124a4 on wasix
  Type "help", "copyright", "credits" or "license" for more information.
  warning: can't use pyrepl: No module named 'msvcrt'
  >>>
shakna 4 hours ago | parent [-]

That sounds like the compilation is accidentally triggering this old frustration [0].

[0] https://github.com/python/cpython/issues/131189

behnamoh 2 hours ago | parent [-]

Compilation was slow for me on macOS too.

syrusakbary an hour ago | parent [-]

We'll improve this very soon, right now the experience is less than ideal.

Ideally we would download the compiled artifacts instead of compiling as Simon commented... it will be a much better experience for everyone!