Seems a lot of work to me. Is this really the best way to create and run Python sandboxes?
Seems a lot of work to me. Is this really the best way to create and run Python sandboxes?
I'm hoping some day to find a recipe I really like for running Python code in a WASM container directly inside Python. Here's the closest I've got, using wasmtime: https://til.simonwillison.net/webassembly/python-in-a-wasm-s...
much better than calling deno, at least if you have no pip dependencies...
just had to update to new api:
# store.add_fuel(fuel) store.set_fuel(fuel) fuel_consumed=fuel-store.get_fuel()
and it works!!
time to hello world: hello_wasm_python311.py 0.20s user 0.03s system 97% cpu 0.234 total
0.000636230 seconds time elapsed
0.000759000 seconds user
0.000000000 seconds sys
That's 36,800% faster. Hand-written assembly was very slightly slower. Using the standard library for output instead of a syscall brought it down to 20,900% faster.(Yes I used percentages to underscore how big the difference is. It's 368x and 209x respectively. That's huge.)
Begrudgingly, here are the standard Python numbers:
real 0m0.019s
user 0m0.015s
sys 0m0.004s
About 1230% faster than the sandbox, i.e. 12.3x. About an order of magnitude, which is typical for these kinds of exercises.Will come with MacOS support very soon :) Does work on Linux
[edit] looks really simple, except I'll have to look into how their raw-exec takes care of writeableRoots: https://github.com/openai/codex/blob/0d6a98f9afa8697e57b9bae...
[edit2] lol raw-exec doesn't do anything at all with writeableRoots, it's handled in the fullPolicy (from scopedWritePolicy)
https://gist.github.com/fzzzy/319d6cbbdfff9c340d0e9c362247ae...
Apple's equivalent is the Apple Virtualization Framework which exposes kvm like functionality at a higher level.