Skip to main content
function Wasm.instantiate
def Wasm.instantiate(
path: str,
/,
*,
args: list[str] = [],
env: dict[str, str] = ,
preopened_dirs: dict[str, str] = ,
inherit_stdio: bool = True,
imports: dict[str, dict[str, typing.Any]] = 
) -> Instance
Instantiate a WASM module with optional WASI configuration and host function imports.

Example

Host Function Signature

Host functions receive two injected arguments followed by WASM arguments:
  • ctx - Task context (currently None, reserved for future use)
  • memory - WASM memory access (currently None, reserved for future use)
  • Additional arguments correspond to the WASM function signature
Return values are converted back to WASM types. Use tuples for multi-value returns. Parameters
  • path: - Path to the WASM binary file
  • args: - Command-line arguments to pass to the WASM module (WASI)
  • env: - Environment variables to set for the WASM module (WASI)
  • preopened_dirs: - Directories to pre-open for filesystem access (WASI). Keys are host paths, values are guest paths.
  • inherit_stdio: - Whether to inherit stdin/stdout/stderr from the host (default: true)
  • imports: - Host function imports, organized by module name and function name. Important: Host functions must be imported from a loaded module via load(), not defined in the same file. This ensures they are frozen and can be safely stored in the WASM runtime.