Metadata-Version: 2.1
Name: wasm_py_sandbox
Version: 0.1.1
Summary: Sandbox environment for executing Python code
Home-page: https://github.com/JSH32/PySandbox
Author: Josh Rudnik
Author-email: rudnik7000@gmail.com
License: MIT
Project-URL: Documentation, https://github.com/JSH32/PySandbox
Project-URL: Bug Reports, https://github.com/JSH32/PySandbox/issues
Project-URL: Source Code, https://github.com/JSH32/PySandbox
Keywords: python,sandbox,wasm,wasmer
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: wasmer==1.1.0
Requires-Dist: wasmer-compiler-cranelift==1.1.0

# 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](https://github.com/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 `wasm32-wasi` runtime which would effectively sandbox it.
  - We use [WAI](https://github.com/wasmerio/wai) to generate glue implementations that we can use to interop between a regular Python environment and RustPython.
- 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](https://github.com/wasmerio/wai).
- To compile the Rust code to a WASI binary, run `cargo build --release --target wasm32-wasi`
  - Replace `py_sandbox/py_sandbox.wasm` with `target/wasm32-wasi/release/py_sandbox.wasm` after building to see changes.
- To build new `bindings.py` from `sandbox.wai`, run `wai-bindgen wasmer-py --import ./sandbox.wai`

## Usage
```py
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)
```
