WebAssembly: Adding Python support to WASM language runtimes
1–10 of 88 posts
Re: WebAssembly: Adding Python support to WASM language runtimes
#2Re: WebAssembly: Adding Python support to WASM language runtimes
#3The 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 my stored data" - without them being able to break my system.
This feels like it should be pretty easy with WebAssembly! It's the classic code sandboxing problem - long a big challenge in Python world - finally solved in a robust way.
I've been finding it surprisingly hard to get a proof-of-concept of this working though.
Essentially I want to be able to do this, in my regular Python code:
import some_webassembly_engine
python = some_webassembly_engine.load(
"python.wasm",
max_cpu_time_in_seconds=3.0,
max_allowed_memory_in_bytes=32000000
)
result = python.execute("3 + 5")
I've not yet figured out the incantations I need to actually do this - in particular the limits on CPU and memory time.I posed this question on Mastodon recently and Jim Kring put together this demo, which gets most of the way there (albeit using an old Python 3.6 build): https://github.com/jimkring/python-sandbox-wasm
It doesn't feel like this should be as hard to figure out as it is!
Re: WebAssembly: Adding Python support to WASM language runtimes
#4Is it just the sandbox or is there anything else I'm missing?
Re: WebAssembly: Adding Python support to WASM language runtimes
#5I'm excited for pairing wasm with WebGPU, which will likely unblock these projects from building support for the web/untrusted ecosystem. A useful project would be one that makes this integration really easy to build today and a flip of the switch to turn on in the future.
Re: WebAssembly: Adding Python support to WASM language runtimes
#6the 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…
Re: WebAssembly: Adding Python support to WASM language runtimes
#7So for someone who has python installed locally, what's the point? Is it just the sandbox or is there anything else I'm missing?
Re: WebAssembly: Adding Python support to WASM language runtimes
#8This 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…
Re: WebAssembly: Adding Python support to WASM language runtimes
#9So for someone who has python installed locally, what's the point? Is it just the sandbox or is there anything else I'm missing?
Re: WebAssembly: Adding Python support to WASM language runtimes
#10This 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…
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 compatibility is pretty good and issues mostly show up around extension modules.