Python sandbox library for python, uses WASM/WASI for isolation.
MIT License
This python sandbox uses wasmer to execute untrusted python code in a sandbox. It is expiremental and limited in functionality. This was designed to be used in an assignment autograder.
wasm32-wasi
runtime which would effectively sandbox it.You will need Rust and wai-bindgen
installed from WAI.
cargo build --release --target wasm32-wasi
py_sandbox/py_sandbox.wasm
with target/wasm32-wasi/release/py_sandbox.wasm
after building to see changes.bindings.py
from sandbox.wai
, run wai-bindgen wasmer-py --import ./sandbox.wai
from wasm_py_sandbox import create_sandbox
# each sandbox has its own memory.
sandbox = create_sandbox()
# returns stdout/err
stdout = sandbox.exec("""
def hello(x):
return x + 5
""")
# result has both stdout/err and return value
result = sandbox.eval("2+2")
print(result.value.value)