Live data from Hacker News

WebAssembly: Adding Python support to WASM language runtimes

wasmlabs.dev

61–70 of 88 posts

Re: WebAssembly: Adding Python support to WASM language runtimes

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

Have you seen Extism? We call it a "plugin system", but it's far more generic than that.. just hard to market a "general purpose universal code runtime".

Python SDK: https://extism.org/docs/integrate-into-your-codebase/python-...

Python is 1 of 15+ languages we support, and as far as I know it's the easiest way to setup a wasm engine in your app, load wasm code, and call a function using complex data I/O.

I'm one of the authors - happy to share more about it, or if you'd like to join our Discord we have lots of active users and contributors there: https://discord.gg/cx3usBCWnc

Re: WebAssembly: Adding Python support to WASM language runtimes

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

Have you seen Extism? We call it a "plugin system", but it's far more generic than that.. just hard to market a "general purpose universal code runtime". Python SDK: https://extism.org/docs/integrate-into-your-codebase/python-... Python is 1 of 15+ languages we support, and as far as I know it's the easiest way to setup a wasm engine in your app, load wasm code, and call a function using complex data I/O. I'm one of…

Oh, and here's an example (test) showing how to construct a "manifest" to control the cpu/memory limits: https://github.com/extism/extism/blob/main/python/tests/test...

cpu is really controlled by # milliseconds until the wasm code is trapped.

Re: WebAssembly: Adding Python support to WASM language runtimes

#63

Earlier quoted context omitted.

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.

Java? .NET?

Re: WebAssembly: Adding Python support to WASM language runtimes

#64

Earlier quoted context omitted.

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.

WASM does not support capability based security that is something of an extension to the WASI proposal.

And even then the security stuff is based on previously existing work in the cloud space. Which has existed for some time but is not widespread.

Re: WebAssembly: Adding Python support to WASM language runtimes

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

I can see that a huge part of the ML space is in python. But is the ML space really such a large community? I mean in the companies I have worked for maybe 1 team in a 100 work with some ML stuff while a large majority of the rest come in contact with web/devops/unix scripting. Granted non ML work takes place in many different languages but python is used alot there.

Re: WebAssembly: Adding Python support to WASM language runtimes

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

Just because python makes sense for ML does not mean that it's primarily used for ML.

Re: WebAssembly: Adding Python support to WASM language runtimes

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

Have you seen Extism? We call it a "plugin system", but it's far more generic than that.. just hard to market a "general purpose universal code runtime". Python SDK: https://extism.org/docs/integrate-into-your-codebase/python-... Python is 1 of 15+ languages we support, and as far as I know it's the easiest way to setup a wasm engine in your app, load wasm code, and call a function using complex data I/O. I'm one of…

I hadn't looked at that one. It looks very promising! Definitely has better documentation than the other options I've looked at.

I see that the library itself is available in Python, but this page https://extism.org/docs/category/write-a-plug-in currently only lists Rust, JavaScript, Go, Haskell, AssemblyScript, Zig and C. Any chance Python might get added to that list as well?

Just found https://github.com/extism/extism-sqlite3 which is very relevant to my interests too!

Re: WebAssembly: Adding Python support to WASM language runtimes

#68

Earlier quoted context omitted.

Have you seen Extism? We call it a "plugin system", but it's far more generic than that.. just hard to market a "general purpose universal code runtime". Python SDK: https://extism.org/docs/integrate-into-your-codebase/python-... Python is 1 of 15+ languages we support, and as far as I know it's the easiest way to setup a wasm engine in your app, load wasm code, and call a function using complex data I/O. I'm one of…

Oh, and here's an example (test) showing how to construct a "manifest" to control the cpu/memory limits: https://github.com/extism/extism/blob/main/python/tests/test... cpu is really controlled by # milliseconds until the wasm code is trapped.

That looks like exactly the level of control I've been hoping for in terms of sandboxing. This is really promising!

Re: WebAssembly: Adding Python support to WASM language runtimes

#69
post #49

Earlier quoted context omitted.

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.

Run it in a docker container?

Re: WebAssembly: Adding Python support to WASM language runtimes

#70
post #22

Earlier quoted context omitted.

It's really hard to do much ML in anything _except_ python. Virtually everyone improving the ML ecosystems of other language got their start in Python and are knowingly competing with Python (e.g. R, Julia). If you want to get started in ML today, python is the obvious easiest path forward. So, most ML users are python users. I don't know how that group compares to non-ML python users, but I have a feeling there isn'…

I found a recentish (2021) survey at [1] which suggests that in 2021 ML was some way behind web development, sysadmin stuff, and data analysis among Python users (and didn't seem to be on the way up the list). [1] https://lp.jetbrains.com/python-developers-survey-2021/#Gene...

The obvious next question being, what's the difference between ML and data analysis from the perspective of the survey participants (is ML a strict subset)? Given the values don't add up to 100%, there's likely lots of overlap and so you could easily have web developers choosing Python for the ML ecosystem.
Post reply on HN