https://github.com/aweirddev/wasm-runtime
WebAssembly-powered, sandboxed implementation of Python runtime.
https://github.com/aweirddev/wasm-runtime
exec python restricted restricted-python runtime sandbox wasm
Last synced: 20 days ago
JSON representation
WebAssembly-powered, sandboxed implementation of Python runtime.
- Host: GitHub
- URL: https://github.com/aweirddev/wasm-runtime
- Owner: AWeirdDev
- License: mit
- Created: 2024-04-28T11:54:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-29T08:27:20.000Z (about 2 years ago)
- Last Synced: 2025-03-18T05:45:25.650Z (about 1 year ago)
- Topics: exec, python, restricted, restricted-python, runtime, sandbox, wasm
- Language: Python
- Homepage: https://pypi.org/project/wasm-runtime
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wasm-runtime
WebAssembly-powered, sandboxed implementation of Python runtime for safely `exec()`-uting dynamic Python code.
This is an active version of [wasm_exec](https://github.com/Jflick58/wasm_exec) created by [Justin Flick](https://github.com/Jflick58).
See [Jflick58/wasm_exec/LICENSE](https://github.com/Jflick58/wasm_exec/blob/main/LICENSE) and [● wasm_runtime/LICENSE](https://github.com/AWeirdDev/wasm_runtime).
`$ pip install wasm-runtime`
## Use
```python
from wasm_runtime import WasmRuntime
runtime = WasmRuntime()
result = runtime.exec("print('Hi, Mom!')")
print(result)
# Result(stdout='Hi, Mom!\n', stderr='', ...)
```
## class WasmRuntime
```python
__init__(
self,
use_fuel: bool = False,
fuel: int = 400_000_000,
runtime_path: str = ""
)
```
Creates a new instance of WebAssembly runtime.
Original code by Justin Flick.
**Args:**
- use_fuel (`bool`): Whether to use fuel.
- fuel (`int`): Fuel.
- runtime_path (`str`): Runtime path. If not specified, the runtime will be downloaded automatically.
### def exec
```python
exec(self, code: str) -> Result
```
Execute Python code.
**Args:**
- code (`str`): Python code.
## dataclass Result
```python
stdout: str
stderr: str
memory_size: int
data_len: int
fuel_consumed: int
```