Live data from Hacker News

WebAssembly: Adding Python support to WASM language runtimes

wasmlabs.dev

41–50 of 88 posts

Re: WebAssembly: Adding Python support to WASM language runtimes

#41
post #18

Earlier quoted context omitted.

I've come across this notion that nowadays machine learning provides (in some sense) the biggest group of Python users a few times recently. What reason is there to suppose this is true? It seems surprising to me.

> What reason is there to suppose this is true? It seems surprising to me. One reason is its just super easy for input output operations. ML is all about data and getting the data to the right place is really easy in python compared to some other languages..

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.

Re: WebAssembly: Adding Python support to WASM language runtimes

#42
post #33

Earlier quoted context omitted.

I don't see how this would in any way prevent you from being affected by a equivalent poisoned pypi dependency; after all your secrets/credentials are inside the sandbox anyways or your code can't work.

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

Re: WebAssembly: Adding Python support to WASM language runtimes

#43
post #2

Ready-to-use python.wasm, also in a Docker+Wasm container image.

But please don't forget to wrap it in at least some VM! /s

That's not even funny, as in real life people would run something like that actually in a VM.

So we have now: HW memory protection -> HW virtualization -> VM -> OS -> Docker -> WASM -> language runtime -> some code snippet.

Things become quite crazy these days, to be honest…

Re: WebAssembly: Adding Python support to WASM language runtimes

#44
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…

FWIW although it's not WebAssembly based, you can do that with GraalVM. It has a concept of language contexts which can be sandboxed including those constraints. There are two caveats: 1. Sandboxing for CPU time and max allowed memory requires the enterprise edition, so you'd have to pay for it. 2. The Python engine isn't 100% compatible with regular Python, although that may not matter for your use case as the compa…

Unfortunately there are at least two more major caveats:

1. Capability control only works for JavaScript (https://www.graalvm.org/latest/reference-manual/embed-langua...)

2. The documentation says in no uncertain terms that running untrusted code is unsupported (https://www.graalvm.org/latest/security-guide/#security-mode...)

Re: WebAssembly: Adding Python support to WASM language runtimes

#46
post #18
post #5

the issue right now with Python support in WASM (at least for machine learning, the main driver of the language) is that Python is largely a wrapper language and none the utilities that make it so powerful (numpy, PyTorch, JAX) work particularly well in wasm, since it's so limited performance-wise (no FMA, no GPU support). I'm excited for pairing wasm with WebGPU, which will likely unblock these projects from buildin…

I've come across this notion that nowadays machine learning provides (in some sense) the biggest group of Python users a few times recently. What reason is there to suppose this is true? It seems surprising to me.

[deleted]

Re: WebAssembly: Adding Python support to WASM language runtimes

#47
post #40
post #28

Earlier quoted context omitted.

Wasmtime's `wasmtime-py` embedding in python has support for Wasm Components: https://github.com/bytecodealliance/wasmtime-py#components (disclosure, I helped create it) The remaining piece of the puzzle would be to create a wit-bindgen guest generator https://github.com/bytecodealliance/wit-bindgen#guests for this build of the python interpreter. You could then seamlessly call back and forth between the host and gue…

If you could provide example code for how to do this - how to run a snippet of untrusted Python code using wasmtime-py with a CPU and RAM limit - I would shout it from the rooftops. I think a LOT of people would benefit from clear examples of how to actually achieve this.

The wit-bindgen work required would be a significant undertaking (a week? more?) by someone who already has some expertise in wit & python. Maybe the wasmlabs folks are up for taking it on.

In general the Wasm Component ecosystem is still a few months away from being generally useful. There are a lot of people across the bytecode alliance working on the fundamentals right now, and we are making great progress, but its not ready to ship quite yet.

Re: WebAssembly: Adding Python support to WASM language runtimes

#48
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…

Depending on what your inputs and outputs look like, perhaps you can spawn the Python interpreter in a subprocess that's sandboxed with seccomp and/or setrlimit?

Re: WebAssembly: Adding Python support to WASM language runtimes

#49
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…

Depending on what your inputs and outputs look like, perhaps you can spawn the Python interpreter in a subprocess that's sandboxed with seccomp and/or setrlimit?

I have not been able to figure out how to do that in the past. I think a solution using those would be restricted to Linux, and I want something that also works on macOS and maybe even Windows too.

Re: WebAssembly: Adding Python support to WASM language runtimes

#50

Earlier quoted context omitted.

> What reason is there to suppose this is true? It seems surprising to me. One reason is its just super easy for input output operations. ML is all about data and getting the data to the right place is really easy in python compared to some other languages..

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)
Post reply on HN