Live data from Hacker News

WebAssembly: Adding Python support to WASM language runtimes

wasmlabs.dev

51–60 of 88 posts

Re: WebAssembly: Adding Python support to WASM language runtimes

#51
post #33

Earlier quoted context omitted.

With Wasm + WASI, you need to explicitly mount files and environment variables. Inside the Wasm VM, the Python interpreter, source code and dependencies only have access to a very reduced surface. Although you're right that if you mount credentials inside, they will be accessible too. The incident I was talking about was the event-stream[1] vulnerability. The attacker introduced code that looked for the data of a cry…

> By default, interpreters may get access to the same resources that the user running the process. In Wasm, the resources are granted manually. What's the difference to run the code under a different user (like for example `nobody` for "full sandboxing", or a "clone of nobody" with some additional access rights)?

Running code under a different user is hard. I don't know how I would do that on macOS, and the times I've done it on Linux I've always had to jump through a bunch of hoops.

Re: WebAssembly: Adding Python support to WASM language runtimes

#52
post #3

This looks very promising! The thing I most want to solve right now is this: I want to write a regular Python application that can safely execute untrusted Python code in a WASM sandbox as part of its execution. I want to do this so I can let end users customize my web applications in weird and interesting ways by pasting their own Python code into a textarea - think features like "run this Python code to transform m…

What kind of Python types do you envision needing to pass across the native/wasm boundary?

Re: WebAssembly: Adding Python support to WASM language runtimes

#53
post #51

Earlier quoted context omitted.

> By default, interpreters may get access to the same resources that the user running the process. In Wasm, the resources are granted manually. What's the difference to run the code under a different user (like for example `nobody` for "full sandboxing", or a "clone of nobody" with some additional access rights)?

Running code under a different user is hard. I don't know how I would do that on macOS, and the times I've done it on Linux I've always had to jump through a bunch of hoops.

MacOS aside, as this is not a serous operating system for this kind of workloads, do you think the "hoops" (which actually?) one needs to "jump through" are so problematic that it makes sense to create millions of lines of new code just to work around them? Only to arrive at the same result that is already working since something around 50 years? This must be really grave issues with just running a task as a different user… Could you expand on that?

Re: WebAssembly: Adding Python support to WASM language runtimes

#54
post #51

Earlier quoted context omitted.

Running code under a different user is hard. I don't know how I would do that on macOS, and the times I've done it on Linux I've always had to jump through a bunch of hoops.

MacOS aside, as this is not a serous operating system for this kind of workloads, do you think the "hoops" (which actually?) one needs to "jump through" are so problematic that it makes sense to create millions of lines of new code just to work around them? Only to arrive at the same result that is already working since something around 50 years? This must be really grave issues with just running a task as a differen…

I want to write software that end users can install on their own machines, that supports plugins so they can execute additional code from untrusted sources.

So macOS needs to work.

Microsoft Flight Simulator uses WebAssembly for its extensions system. I want to do the same thing for my own projects.

Re: WebAssembly: Adding Python support to WASM language runtimes

#55

Earlier quoted context omitted.

Which languages? Python is OOP; but the "classical" data-centric languages are actually all more or less in the FP space. (I count array languages and APL-likes to FP in this case). Just an example: You don't have immutable data types by default in Python. This is actually a pretty bad default for data processing tasks.

Python has a huge library ecosystem and the average Machine Learning programmer is not a CS geek and so prefers pythonic quasi-OOO then over FP (one of the hurdles for JAX adoption is it's functional paradigm)

The claim was that Python is better suited to writing such libs and frameworks than other languages.

You now say it's like that because Python has already quite some libs / frameworks in that direction.

This looks like circular reasoning.

Also the the "prototypical ML dude" comes form the math department. People with math background have a much easier time to grasp FP than procedural programming. FP is much more "natural" when you're used to math.

(Procedural programming says things like `x = x + 1`, but even my grandma would know that "this has no solution", or is likewise "plain wrong" ;-))

Re: WebAssembly: Adding Python support to WASM language runtimes

#56
post #25

Earlier quoted context omitted.

The startup I'm working at is basically trying to do exactly that as a service, but a one-off thing for a regular Python application shouldn't be as hard to figure out as it is. Can you link to the Mastodon thread (darn lack of search!) and we can continue there?

Here's the Mastodon conversation: https://fedi.simonwillison.net/@simon/109682777068881522 (I'm so close to building my own search engine just against my own content there.)

I have Covid and it's late in the UK, but tried poking at wasmtime-py for the first time and got this far: https://gist.github.com/callahad/81b33e4e4456e4b27a5934c1a36...

If anyone else is awake and wants to pick up the baton...

- CPU limits are just using an arbitrary amount of wasmtime "fuel". Would be worth looking into epoch interrupts instead.

- Memory limits aren't implemented. Seems like wasmtime-py doesn't expose bindings to anything with a wasmtime::ResourceLimiter trait.

- All i/o is going through tempfiles instead of dealing with proper interfaces.

Re: WebAssembly: Adding Python support to WASM language runtimes

#57
post #11

There seems to be so many different variants of the same thing out there. What makes this unique? For example I know Pyodide exists and also runs CPython under WASM.

This one is designed to run on the server side and interface with the OS via WASI, so it can read/write files etc

Pyodide can do so too, though through an emscripten interface. I managed to get it running on Cloudflare Workers as a POC[0] (though I should add a disclaimer that I work at Cloudflare)

0 - https://github.com/dom96/pycloud

Re: WebAssembly: Adding Python support to WASM language runtimes

#58
post #39

Earlier quoted context omitted.

Why do this on the client? Why not pass it to the server and run it on Python there?

That's what I'm talking about: I want to run Python code on my server, but since it's from an untrusted source I want to make sure that it's in a sandbox with strict limits on what it can do, how much CPU it can use and how much RAM it has available to it - so malicious code can't be used to crash my server or steal data it shouldn't have access to.

How do you think WASM will solve this where everything else has failed?

Re: WebAssembly: Adding Python support to WASM language runtimes

#59
post #39

Earlier quoted context omitted.

That's what I'm talking about: I want to run Python code on my server, but since it's from an untrusted source I want to make sure that it's in a sandbox with strict limits on what it can do, how much CPU it can use and how much RAM it has available to it - so malicious code can't be used to crash my server or steal data it shouldn't have access to.

How do you think WASM will solve this where everything else has failed?

Because WASM supports capability based security and thus never trusts code to do the right thing. Unlike every single one of it's predecessors.

Re: WebAssembly: Adding Python support to WASM language runtimes

#60
post #3

This looks very promising! The thing I most want to solve right now is this: I want to write a regular Python application that can safely execute untrusted Python code in a WASM sandbox as part of its execution. I want to do this so I can let end users customize my web applications in weird and interesting ways by pasting their own Python code into a textarea - think features like "run this Python code to transform m…

https://nsjail.dev is a common tool for sandboxing
Post reply on HN