Python Sandbox
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.
Components
- Rust WASM layer
- RustPython is used as a dependency in the rust part of this library. RustPython doesn't aim to create sandboxed environments but we can create a simple API for interacting with it while it is being run in a
wasm32-wasiruntime which would effectively sandbox it. - We use WAI to generate glue implementations that we can use to interop between a regular Python environment and RustPython.
- RustPython is used as a dependency in the rust part of this library. RustPython doesn't aim to create sandboxed environments but we can create a simple API for interacting with it while it is being run in a
- Python Layer
- The Python bindings are also generated with WAI and a helper is provided for setup.
Development
You will need Rust and wai-bindgen installed from WAI.
- To compile the Rust code to a WASI binary, run
cargo build --release --target wasm32-wasi- Replace
py_sandbox/py_sandbox.wasmwithtarget/wasm32-wasi/release/py_sandbox.wasmafter building to see changes.
- Replace
- To build new
bindings.pyfromsandbox.wai, runwai-bindgen wasmer-py --import ./sandbox.wai
Usage
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)
Metadata
Release files for wasm-py-sandbox 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| wasm_py_sandbox-0.1.1.tar.gz | 3.5 MB | Without provenance | Details for wasm_py_sandbox-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| wasm_py_sandbox-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for wasm_py_sandbox-0.1.1-py3-none-any.whl |
Total release size: 7.0 MB
Release files / wasm_py_sandbox-0.1.1.tar.gz
| Download URL | wasm_py_sandbox-0.1.1.tar.gz |
|---|---|
| Size | 3.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73f11645ffc92211aed994d44538547355b75993cc468cad94d087107e5c83a2
|
|
BLAKE2b-256 checksum How to use checksums |
9aa56466821c56b73de3494a7d95240a3152d945b2c9da0ae86d78926143ef38
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Release files / wasm_py_sandbox-0.1.1-py3-none-any.whl
| Download URL | wasm_py_sandbox-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.5 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4989f407bd3ebbb108601e28fe5f426a47bc12df422b7eeefa120d34b35b512d
|
|
BLAKE2b-256 checksum How to use checksums |
1a266254051a77dbec826c100b3a19a085d21856c2449c0a10b6e7ff9d9d44ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.12
|
Security for wasm-py-sandbox 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.