Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.



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


I 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


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


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.


What's wrong with Docker for this?


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


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


I'm concerned about prompt injection attacks telling the LLM how to escape the Docker container.

You can almost think of a prompt injection attack as a supply chain attack - but regular supply chain attacks are a concern too, what if an LLM installs a new version of an NPM package that turns out to have been deliberately infected with malware that can escape a container?


When you use docker you can have full control over the networking layer already. As you can bound it's networking to another container that will act as proxy/filter. How WASM offer that?

With reverse proxy you can log requests, or filter them if needed, restrict the allowed domains, do packet inspection if you want to go crazy mode.

And if an actor is able to tailor fit a prompt to escape docker, I think you have bigger issues in your supply chain.

I feel this wasm is bad solution. What it brings a VM or docker can't do?

And escaping a docker container is not that simple, require a lot of heavy lifting and not always possible.


Aside from my worries about container escape, my main problem with Docker is the overhead of setting it up.

I want to build software that regular users can install on their own machines. Telling them they have to install Docker first is a huge piece of friction that I would rather avoid!

The lack of network support for WASM fits my needs very well. I don't want users running untrusted code which participates in DDoS attacks, for example.


You have the same lack of network support with cgroups containers if you configure them properly. It isn't as if it's connected and filtered out, but as though it's disconnected. You can have it configured in such a way that it has network support but that it's filtered out with iptables, but that does seem more dangerous, though in practice that isn't where the escapes are coming from. A network namespace can be left empty, without network interfaces, and a process made to use the empty namespace. That way there isn't any traffic flowing from an interface to be checked against iptables rules.

Escaping a container is apparently much easier than escaping a VM.


I think that threat is generally overblown in these discussions. Yes, container escape is less difficult than VM escape, but it still requires major kernel 0day to do; it is by no means easy to accomplish. Doubly so if you have some decent hygiene and don't run anything as root or anything else dumb.

When was the last time we have heard container escape actually happening?


Just because you haven't heard of it doesn't mean the risk isn't real.

It's probably better to make some kind of risk assessment and decide whether you're willing to accept this risk for your users / business. And what you can do to mitigate this risk. The truth is the risk is always there and gets smaller as you add several isolation mechanisms to make it insignificant.

I think you meant “container escape is not as difficult as VM escape.” A malicious workload doesn’t need to be root inside the container, the attack surface is the shared linux kernel.

Not allowing root in a container might mitigate a container getting root access outside of a namespace. But if an escape succeeds the attacker could leverage yet another privilege escalation mechanism to go from non-root to root


To quote one of HN's resident infosec experts: Shared-kernel container escapes are found so often they're not even all that memorable.

More here: https://news.ycombinator.com/item?id=32319067


apparently...

Like it's also possible in a VM.

What about running non privileged containers! You need really to open some doors to make it easier!


Better not rely on unprivileged containers to save you. The problem is:

Breaking out of a VM requires a hypervisor vulnerability, which are rare.

Breaking out of a shared-kernel container requires a kernel syscall vulnerability, which are common. The syscall attack surface is huge, and much of it is exploitable even by unprivileged processes.

I posted this thread elsewhere here, but for more info: https://news.ycombinator.com/item?id=32319067


Is Podman unescapable compared to Docker?


They both use the same fundamental isolation mechanisms, so no.


They both can be highly unescapable. The podman community is smaller but it's more focused on solving technical problems than docker is at this point, which is trying to increase subscription revenue. I have gotten a configuration for running something in isolation that I'm happy with in podman, and while I think I could do exactly the same thing in Docker, it seems simpler in podman to me.

Apologies for repeating myself all over this part of the thread, but the vulnerabilities here are something that Podman and Docker can't really do anything about as long as they're sharing a kernel between containers.

The vulnerability is in kernel syscalls. More info here: https://news.ycombinator.com/item?id=32319067

If you're going to make containers hard to escape, you have to host them under a hypervisor that keeps them apart. Firecracker was invented for this. If Docker could be made unescapable on its own, AWS wouldn't need to run their container workloads under Firecracker.


This same, not especially informative content is being linked to again and again in this thread. If container escapes are so common, why has nobody linked to any of them rather than a comment saying "There are lots" from 3 years ago?

I did apologize, didn't I? :-)

Perspective is everything, I guess. You look at that three year old comment and think it's not particularly informative. I look at that comment and see an experienced infosec pro at Fly.io, who runs billions of container workloads and doesn't trust the cgroups+namespaces security boundary enough so goes to the trouble of running Firecracker instead. (There are other reasons they landed there, but the security angle's part of it.)

Anyway if you want some links, here are a few. If you want more, I'm sure you can find 'em.

CVE-2022-0492: https://unit42.paloaltonetworks.com/cve-2022-0492-cgroups

CVE-2022-0847: https://www.datadoghq.com/blog/engineering/dirty-pipe-contai...

CVE-2023-2640: https://www.crowdstrike.com/en-us/blog/crowdstrike-discovers...

CVE-2024-21626: https://nvd.nist.gov/vuln/detail/cve-2024-21626

Some are covered off by good container deployment hygiene and reducing privilege, but from my POV it looks like the container devs are plugging their fingers in a barrel that keeps springing new leaks.

(To be fair, modern Docker's a lot better than it used to be. If you run your container unprivileged and don't give it extra capabilities and don't change syscall filters or MAC policies, you've closed off quite a bit of the attack surface, though far from all of it.)

But keep in mind that shared-kernel containers are only as secure as the kernel, and today's secure kernel syscall can turn insecure tomorrow as the kernel evolves. There are other solutions to that (look into gVisor and ask yourself why Google went to the trouble to make it -- and the answer is not "because Docker's security mechanisms are good enough"), but if you want peace of mind I believe it's better to sidestep the whole issue by using a hypervisor that's smaller and much more auditable than a whole Linux kernel shared across many containers.


I mean docker runs in sudo privileges for the most part, yes I know that docker can run rootless too but podman does it out of the box.

So if your docker container gets vulnerable and it can somehow break through a container, I think that with default sudo docker, you might get sudo privileges whereas in default podman, you would be having it as a user run executable and might need another zero day or smth to have sudo privilege y'know?


Docker would be hacky and cumbersome especially when compared to anything assembly like.


The sandboxing, especially for AI Agents.


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.


Ideally, something that we could share between JS and Python.


Hasn't Pyodide been available for some years now?


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


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


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?


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


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


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


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.


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


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


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


Any chance your deno thing is on GH?


Yup, github.com/gvkhna/vibescraper in the sandbox package. Def needs a cleanup but it’s heavily tested and works great at aivibescraper.com

Bummer. Back to Docker then.


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


``` ╰─ wasmer run python/python

error: Spawn failed

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

```


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


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.


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.


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?


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!


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


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

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


Compilation was slow for me on macOS too.


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!


It says the same thing in the pyodide repl for what it's worth.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: