Skip to main content
The Palyra plugin system provides a high-performance, secure, and resource-constrained environment for executing third-party code. It utilizes WebAssembly (WASM) to ensure hardware-level isolation while providing a rich set of host capabilities via a specialized SDK and WIT-based interface.

Runtime Architecture

The palyra-plugins-runtime is built on top of Wasmtime and Cranelift. It is responsible for instantiating WASM modules, enforcing resource quotas (fuel and memory), and providing the “bridge” between the guest WASM module and the Palyra host services.

Key Components

WasmRuntime Execution Flow

The following diagram illustrates the lifecycle of a plugin execution from the daemon’s perspective. Plugin Execution Sequence Sources: crates/palyra-plugins/runtime/src/lib.rs#152-186, crates/palyra-daemon/src/wasm_plugin_runner.rs#114-126

Resource Limits & Fuel Budgets

To prevent Resource Exhaustion attacks, the runtime enforces strict limits defined in RuntimeLimits crates/palyra-plugins/runtime/src/lib.rs#24-29.
LimitDescriptionDefault Value
fuel_budgetMaximum instructions allowed (Wasmtime fuel)10,000,000
max_memory_bytesLinear memory allocation limit64 MiB
max_table_elementsMaximum elements in WASM tables100,000
max_instancesMaximum concurrent module instances256
The WasmPluginRunnerPolicy in the daemon further refines these limits and adds higher-level constraints such as max_module_size_bytes crates/palyra-daemon/src/wasm_plugin_runner.rs#18-30. Sources: crates/palyra-plugins/runtime/src/lib.rs#31-40, crates/palyra-daemon/src/wasm_plugin_runner.rs#18-30

Host Capabilities & SDK Interface

Plugins do not have direct access to the network, filesystem, or secrets. Instead, they must request capabilities in their manifest, which are then mapped to integer handles at runtime.

Capability Import Interface

The host exports several functions to the guest under the palyra:host/capabilities module (defined by HOST_CAPABILITIES_IMPORT_MODULE crates/palyra-plugins/runtime/src/lib.rs#3-9).
  • Count Functions: Returns the number of granted items for a category (e.g., host_capability_http_count).
  • Handle Functions: Returns a handle for a specific index (e.g., host_capability_http_handle).

Handle Range Mapping

To prevent handle confusion, handles are partitioned into specific ranges:
  • HTTP: 10,000+
  • Secrets: 20,000+
  • Storage: 30,000+
  • Channels: 40,000+
Capability Mapping Entity Relationship Sources: crates/palyra-plugins/runtime/src/lib.rs#16-19, crates/palyra-plugins/runtime/src/lib.rs#63-81, crates/palyra-daemon/src/wasm_plugin_runner.rs#71-82

Implementation Details

Module Resolution

The WasmPluginRunner in the daemon handles the resolution of WASM bytes from multiple sources crates/palyra-daemon/src/wasm_plugin_runner.rs#179-182:
  1. Inline Payloads: module_wat (WebAssembly Text) or module_base64 crates/palyra-daemon/src/wasm_plugin_runner.rs#202-213.
  2. Installed Skills: Resolving a skill_id and tool_id to a specific .wasm file within the skill’s directory crates/palyra-daemon/src/wasm_plugin_runner.rs#85-94.

Error Handling

The runtime distinguishes between different failure modes using the RuntimeError enum crates/palyra-plugins/runtime/src/lib.rs#90-103:
  • Compile: Validation or compilation failure.
  • ExecutionLimitExceeded: Guest ran out of fuel or memory.
  • ExecutionTimedOut: Wall-clock timeout triggered by epoch interruption.
The daemon maps these to WasmPluginRunErrorKind for the Gateway response crates/palyra-daemon/src/wasm_plugin_runner.rs#44-51. Sources: crates/palyra-daemon/src/wasm_plugin_runner.rs#96-126, crates/palyra-plugins/runtime/src/lib.rs#90-103