This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: wasi-preview2-canonical-abi-isolation

WASI 0.2 Component Model Shared-Nothing Sandbox Guardrail

Enforces strict canonical ABI boundaries and shared-nothing memory isolation across WebAssembly Component Model (WASI 0.2) interfaces. Prevents arbitrary host-guest pointer passing, raw linear memory sharing, and unconstrained capability grants when executing untrusted dynamic plugins. Guarantees that communication across component boundaries uses exclusively WIT (Wasm Interface Type) declarations with canonical serialization and explicit host resource handle lifecycles.

Prohibited Anti-Pattern: Exposing Raw Linear Memory Pointers or Direct Host Capabilities to Guest Components

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WASI 0.2 Component Model Shared-Nothing Sandbox Guardrail - Enforces strict canonical ABI boundaries and shared-nothing memory isolation across WebAssembly Component Model (WASI 0.2) interfaces. Prevents arbitrary host-guest pointer passing, raw linear memory sharing, and unconstrained capability grants when executing untrusted dynamic plugins. Guarantees that communication across component boundaries uses exclusively WIT (Wasm Interface Type) declarations with canonical serialization and explicit host resource handle lifecycles.
globs: src/**/*.wit, src/**/*.{rs,ts,go,cpp}, wit/**/*.wit
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/wasi-preview2-canonical-abi-isolation"
---

# WASI 0.2 Component Model Shared-Nothing Sandbox Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing Raw Linear Memory Pointers or Direct Host Capabilities to Guest Components

## System Constraints
You are a Principal Security Architect enforcing the WASI 0.2 (Preview 2) Component Model Shared-Nothing Sandbox Standard. Mandate strict adherence to WIT-defined boundaries, canonical ABI validation, zero-shared linear memory, and capability-based security. Reject any code pattern attempting raw pointer arithmetic into guest memory, unmanaged FFI bindings, unmediated system access, or persistent unmonitored handle leakage.

## Strict Guidelines
- Components MUST communicate exclusively via WebAssembly Interface Types (WIT) contracts; direct linear memory buffer addresses MUST NOT cross component boundaries.
- Engineers MUST NOT grant raw file system paths, ambient network sockets, or root environment blocks to guest instances without capability scoping through WASI Resource handles.
- Host runtimes MUST copy or canonically lift/lower data across the boundary using the Canonical ABI rather than casting raw internal pointers.
- Untrusted plugin invocations MUST be wrapped in explicit fuel/epoch deadlines and isolated ResourceTable tracking to prevent memory exhaustion and infinite loops.
- Host functions exposed to guest components MUST validate all parameter invariant lengths and reject invalid UTF-8 byte streams prior to execution.
- Components NEVER receive ambient authority; all I/O handles MUST derive from parent-governed virtualized capabilities (e.g., wasi:filesystem/preopens).

## Bad vs Good Implementations
### Wasmtime Host Binding: Unsafe Memory Dereference vs. Canonical WIT Resource Implementation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly accessing guest linear memory via raw pointers circumvents the Component Model's Shared-Nothing boundary. This exposes the host to out-of-bounds memory reads, race conditions, and memory corruption if the guest dynamically alters memory layout or passes invalid offsets.
```rust
// ANTI-PATTERN: Bypassing Component Model via legacy core Wasm raw pointer dereferencing
use wasmtime::*;

pub fn execute_untrusted_plugin(
    mut store: Store<()>,
    instance: &Instance,
    ptr: u32,
    len: u32,
) -> Result<String, Box<dyn std::error::Error>> {
    let memory = instance.get_memory(&mut store, "memory")
        .ok_or("missing linear memory")?;
    
    // VULNERABILITY: Raw guest pointer dereference susceptible to out-of-bounds read and memory corruption
    let data = unsafe {
        let mem_ptr = memory.data_ptr(&store).add(ptr as usize);
        std::slice::from_raw_parts(mem_ptr, len as usize)
    };
    
    Ok(std::str::from_utf8(data)?.to_string())
}
```

#### Production Standard (Correct)
> **Standard**: Adheres to WASI 0.2 Component Model standards using generated typed bindings (bindgen). Guest input and output are safely serialized/deserialized across isolated linear memories through the Canonical ABI without exposing raw pointers. Timeouts are enforced via epoch-based trapping.
```rust
// PRODUCTION STANDARD: Shared-Nothing WASI 0.2 Component with Canonical ABI Lift/Lower
use wasmtime::component::*;
use wasmtime::{Config, Engine, Store};

bindgen!({ 
    world: "secure-plugin",
    inline: "
        package local:sandbox;
        world secure-plugin {
            import host-logger: func(msg: string);
            export process-payload: func(input: list<u8>) -> result<string, string>;
        }
    "
});

pub fn execute_untrusted_plugin(
    engine: &Engine,
    component: &Component,
    payload: Vec<u8>,
) -> Result<String, Box<dyn std::error::Error>> {
    let mut linker = Linker::new(engine);
    SecurePlugin::add_to_linker(&mut linker, |state: &mut HostState| state)?;

    let mut store = Store::new(engine, HostState::default());
    // Enforce capability bounds and resource limits via epoch/fuel
    store.set_epoch_deadline(1);

    let plugin = SecurePlugin::instantiate(&mut store, component, &linker)?;
    
    // Canonical ABI handles copying, bounds-checking, and type validation securely
    match plugin.call_process_payload(&mut store, &payload)? {
        Ok(result) => Ok(result),
        Err(err) => Err(format!("Guest processing failed: {}", err).into()),
    }
}

#[derive(Default)]
pub struct HostState;
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: WASI 0.2 Component Model Shared-Nothing Sandbox Guardrail

WASI 0.2 Component Model Shared-Nothing Sandbox Guardrail defines an industrial-grade behavioral standard for security engineering. Enforces strict canonical ABI boundaries and shared-nothing memory isolation across WebAssembly Component Model (WASI 0.2) interfaces. Prevents arbitrary host-guest pointer passing, raw linear memory sharing, and unconstrained capability grants when executing untrusted dynamic plugins. Guarantees that communication across component boundaries uses exclusively WIT (Wasm Interface Type) declarations with canonical serialization and explicit host resource handle lifecycles. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Exposing Raw Linear Memory Pointers or Direct Host Capabilities to Guest Components Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftExposing Raw Linear Memory Pointers or Direct Host Capabilities to Guest ComponentsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Components MUST communicate exclusively via WebAssembly Interface Types (WIT) contracts

Components MUST communicate exclusively via WebAssembly Interface Types (WIT) contracts; direct linear memory buffer addresses MUST NOT cross component boundaries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT grant raw file system paths, ambient network sockets, or root environment blocks to guest instances without capability scoping through WASI Resource handles.

Engineers MUST NOT grant raw file system paths, ambient network sockets, or root environment blocks to guest instances without capability scoping through WASI Resource handles.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Host runtimes MUST copy or canonically lift/lower data across the boundary using the Canonical ABI rather than casting raw internal pointers.

Host runtimes MUST copy or canonically lift/lower data across the boundary using the Canonical ABI rather than casting raw internal pointers.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Untrusted plugin invocations MUST be wrapped in explicit fuel/epoch deadlines and isolated ResourceTable tracking to prevent memory exhaustion and infinite loops.

Untrusted plugin invocations MUST be wrapped in explicit fuel/epoch deadlines and isolated ResourceTable tracking to prevent memory exhaustion and infinite loops.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Host functions exposed to guest components MUST validate all parameter invariant lengths and reject invalid UTF-8 byte streams prior to execution.

Host functions exposed to guest components MUST validate all parameter invariant lengths and reject invalid UTF-8 byte streams prior to execution.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

Components NEVER receive ambient authority

Components NEVER receive ambient authority; all I/O handles MUST derive from parent-governed virtualized capabilities (e.g., wasi:filesystem/preopens).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is WASI 0.2 Component Model Shared-Nothing Sandbox Guardrail critical for AI coding assistants?

Enforces strict canonical ABI boundaries and shared-nothing memory isolation across WebAssembly Component Model (WASI 0.2) interfaces. Prevents arbitrary host-guest pointer passing, raw linear memory sharing, and unconstrained capability grants when executing untrusted dynamic plugins. Guarantees that communication across component boundaries uses exclusively WIT (Wasm Interface Type) declarations with canonical serialization and explicit host resource handle lifecycles. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Exposing Raw Linear Memory Pointers or Direct Host Capabilities to Guest Components) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

WASI