Skip to content

AWeirdDev/wasm-runtime

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wasm-runtime

WebAssembly-powered, sandboxed implementation of Python runtime for safely exec()-uting dynamic Python code.

This is an active version of wasm_exec created by Justin Flick.
See Jflick58/wasm_exec/LICENSE and ● wasm_runtime/LICENSE.

$ pip install wasm-runtime


Use

from wasm_runtime import WasmRuntime

runtime = WasmRuntime()
result = runtime.exec("print('Hi, Mom!')")

print(result)
# Result(stdout='Hi, Mom!\n', stderr='', ...)

class WasmRuntime

__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

exec(self, code: str) -> Result

Execute Python code.

Args:

  • code (str): Python code.

dataclass Result

stdout: str
stderr: str
memory_size: int
data_len: int
fuel_consumed: int

Releases

No releases published

Packages

No packages published

Languages