Live data from Hacker News

WebAssembly: Adding Python support to WASM language runtimes

wasmlabs.dev

81–88 of 88 posts

Re: WebAssembly: Adding Python support to WASM language runtimes

#81
post #78
post #75

Earlier quoted context omitted.

Containers and similar OS security features already provide that.

Exploring and providing new and different approaches is worthwhile, and I doubt the tradeoffs of each technology is identical.

Except these aren't new approaches.

https://www.ibm.com/docs/en/zos/2.4.0?topic=descriptions-lan...

Re: WebAssembly: Adding Python support to WASM language runtimes

#82
post #75

Earlier quoted context omitted.

Containers and similar OS security features already provide that.

Not with that level of granularity. Wasm is able to run in severely constrained environments (ie microcontrollers) and non-posix OS that may not be able to support containers

Like Western Digital having hard disk controllers running P-Code in 1979.

https://en.wikipedia.org/wiki/Pascal_MicroEngine

Re: WebAssembly: Adding Python support to WASM language runtimes

#83
post #82

Earlier quoted context omitted.

Not with that level of granularity. Wasm is able to run in severely constrained environments (ie microcontrollers) and non-posix OS that may not be able to support containers

Like Western Digital having hard disk controllers running P-Code in 1979. https://en.wikipedia.org/wiki/Pascal_MicroEngine

Sure. Everything in computing pretty much builds on top of everything else. Wasm is no different and incorporates a lot of the learnings from previous technologies like Java and .NET

Re: WebAssembly: Adding Python support to WASM language runtimes

#84

Sidenote: WasmEdge 0.12 (to be released in Feb) will be fully compatible with wasmtime’s socket API. There will be no need for separate builds soon. In addition to wasmtime socket, WasmEdge supports async non-blocking socket for high-performance apps

Looking forward to it!

Re: WebAssembly: Adding Python support to WASM language runtimes

#85
post #73
post #40

Earlier quoted context omitted.

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.

is this close to what you had in mind? https://gist.github.com/pims/711549577759ad1341f1a90860f1f3a...

Yes! Very much so.

Just tried this and it works great!

I changed app.py to this:

    import sqlite3
    print(sqlite3.connect(":memory:").execute(
        "select sqlite_version()"
    ).fetchone()[0])
And it output "3.39.2" - but the same code in my regular Python interpreter output "3.40.1", which demonstrates that the WASM Python there has its own WASM-compiled SQLite.

Re: WebAssembly: Adding Python support to WASM language runtimes

#86
post #67

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…

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/ex…

Extism does not yet support writing the plugins (our term for Wasm guests) in python. I have been working on javascript support[1] and I think I could use a similar strategy to support python. If you are at all interested in following along or helping out you should join our discord.[2] I just started a #python-pdk channel there.

[1] https://github.com/extism/js-pdk [2] https://discord.gg/mAADpt9r

Re: WebAssembly: Adding Python support to WASM language runtimes

#87
post #85
post #73

Earlier quoted context omitted.

is this close to what you had in mind? https://gist.github.com/pims/711549577759ad1341f1a90860f1f3a...

Yes! Very much so. Just tried this and it works great! I changed app.py to this: import sqlite3 print(sqlite3.connect(":memory:").execute( "select sqlite_version()" ).fetchone()[0]) And it output "3.39.2" - but the same code in my regular Python interpreter output "3.40.1", which demonstrates that the WASM Python there has its own WASM-compiled SQLite.

Great! I still need to look into how to limit memory consumption. Fuel works well enough for now, but there might be an option to limit execution by time, not just instructions.

Re: WebAssembly: Adding Python support to WASM language runtimes

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

I totally agree with you on how ridiculous this is. But it's all about trade offs in the end. In the case of Docker+Wasm you get portability and delivery speed.

You build one image for the wasm32/wasi platform and now it can run on any architecture that has Docker, just like that. And also you don't carry the whole OS baggage of a typical container. Only the language runtime. So download times are faster.

---

Lastly, the Docker deployment is just the easiest way for a WASM application to reach people. They can try it out without the necessity to setup and support a WASI runtime.

Post reply on HN