> ## Documentation Index
> Fetch the complete documentation index at: https://nekzus-32.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Compiling WASM Payloads

> Creating binary Intelligence for the Mesh Sandbox

When developing directly in the Rust Core (specifically within the `wasm-filters` crate), you are writing the exact logic that an Agent will inject into remote Data Nodes.

Because this logic must be completely OS-agnostic and strictly sandboxed, you cannot compile it targeting standard architectures like `x86_64` or `arm64`. It must be compiled to WebAssembly, explicitly targeting the **WASI (WebAssembly System Interface)** standard.

## Setting up the Compiler Target

Ensure your Rust toolchain has the WASI standard library installed.

```bash theme={null}
rustup target add wasm32-wasi
```

<Note>
  LIOP currently targets WASI Preview 1 (`wasm32-wasi`). We are actively monitoring `wasm32-wasip2` (The Component Model) and will migrate the `Wasmtime` engine to support strongly-typed complex objects crossing the engine boundary in our next release.
</Note>

## Writing a Filter

A typical LIOP Filter is standard Rust code, with the caveat that network and threading operations will panic if invoked, due to the Sandboxing constraints on the destination server.

```rust src/main.rs theme={null}
use std::env;
use std::fs;

fn main() {
    // 1. Receive arguments passed by the Data Node runtime
    let args: Vec<String> = env::args().collect();
    let query = args.get(1).expect("Missing query parameter");

    // 2. Access the virtualized file system
    // /logs is mapped by the Server, not the physical root!
    if let Ok(content) = fs::read_to_string("/logs/system.log") {
        for line in content.lines() {
            if line.contains(query) {
                // 3. Output is trapped by WASI and streamed via gRPC
                println!("{}", line);
            }
        }
    }
}
```

## Compilation

To compile your logic into the `.wasm` injection payload, run Cargo targeting the WASI architecture:

```bash theme={null}
cargo build --target wasm32-wasi --release
```

The resulting microscopic file (e.g., `target/wasm32-wasi/release/filter.wasm`) is what the `liop-client` loads into memory and streams to the peer over the network.

## Testing Locally

Before deploying your filter to the production mesh, you can test its behavior locally using the standalone Wasmtime CLI.

Provide the capability mappings (like pre-opened directories) explicitly:

```bash theme={null}
wasmtime run --dir /local/physical/path::/logs filter.wasm "CRITICAL"
```
