Post ASEpyuVH3b9c4nzrIe by brettcannon@fosstodon.org
(DIR) More posts by brettcannon@fosstodon.org
(DIR) Post #ASEpyu18rd3EZLtnKi by simon@fedi.simonwillison.net
2023-01-13T16:12:39Z
0 likes, 0 repeats
I have a challenge for anyone who likes experimenting with Python and WebAssembly:Produce a short snippet of Python that takes a string of code in some other language (JavaScript, Lua or even Python itself), runs "eval" on it and returns the result, running that eval inside a WASM engine (using wasmer or wasmtime or wasm3) with restriction on the amount of CPU/memory available to that executionIt feels like this should be the "hello world" of WASM but I have not yet figured out how to do it!
(DIR) Post #ASEpyuVH3b9c4nzrIe by brettcannon@fosstodon.org
2023-01-13T20:14:17Z
0 likes, 0 repeats
@simon I don't have the time write now to code up an example, but for wasmtime I think you're looking for its concept of _fuel_, which you can control from their Python API (and CLI): https://bytecodealliance.github.io/wasmtime-py/#wasmtime.Config.consume_fuel
(DIR) Post #ASEpyv2x2O5nlFkknA by jimkring@fosstodon.org
2023-01-14T19:05:44Z
0 likes, 0 repeats
@brettcannon @simon here's something I duct-taped together: https://github.com/jimkring/python-sandbox-wasm
(DIR) Post #ASEpyvd6rx13ZOfd9U by simon@fedi.simonwillison.net
2023-01-14T19:09:58Z
0 likes, 0 repeats
@jimkring @brettcannon this looks AMAZING - thank you so much!
(DIR) Post #ASEpyvkCRagfvNzICe by simon@fedi.simonwillison.net
2023-01-13T16:14:25Z
0 likes, 0 repeats
Even without the sandboxing restrictions, I'd love to see example code that loads up a WASM build of JavaScript/Lua/Python inside a Python host script and executes some code in it - I've not managed to do that yet eitherPart of the challenge is finding a documented .wasm file for one of those languages that I can download and then load inside Python - I really don't want to build one of those from scratch first
(DIR) Post #ASEpyw5p9Bz70S6YuO by jimkring@fosstodon.org
2023-01-14T19:31:23Z
0 likes, 0 repeats
@simon @brettcannon you’re welcome. let me know if you have any questions or issues. I didn’t double-check the setup process and plan to add a GitHub workflow to test it all out on a clean machine.
(DIR) Post #ASEpywZxLA5UVuCcsK by pims@hachyderm.io
2023-02-01T08:13:06Z
0 likes, 1 repeats
@jimkring @simon @brettcannon I took a stab at it: https://gist.github.com/pims/711549577759ad1341f1a90860f1f3a5Works on MacOS ARM.
(DIR) Post #ASEpyxn6pkCeGzMe12 by jimkring@fosstodon.org
2023-01-14T20:50:20Z
0 likes, 0 repeats
@simon I added CI (setup and testing) with github actions. It's passing! 👍 https://github.com/jimkring/python-sandbox-wasm/actions/