This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
frontendcritical PriorityID: wasi-02-canonical-abi-boundary-guardrail

WASI 0.2 Component Model Canonical ABI Boundary & Memory Isolation

Enforces strict sandboxed linear memory isolation and deterministic Canonical ABI serialization across polyglot WebAssembly micro-frontends executing in browser runtimes. Prohibits manual guest memory manipulation, direct ArrayBuffer pointer passing, and out-of-band heap mutation in favor of type-safe WIT (WebAssembly Interface Type) lifting and lowering operations.

Prohibited Anti-Pattern: Bypassing Canonical ABI via Manual Linear Memory Slicing and Raw Heap Allocation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WASI 0.2 Component Model Canonical ABI Boundary & Memory Isolation - Enforces strict sandboxed linear memory isolation and deterministic Canonical ABI serialization across polyglot WebAssembly micro-frontends executing in browser runtimes. Prohibits manual guest memory manipulation, direct ArrayBuffer pointer passing, and out-of-band heap mutation in favor of type-safe WIT (WebAssembly Interface Type) lifting and lowering operations.
globs: src/**/*.{ts,tsx,wit}, packages/*/src/**/*.{ts,tsx,wit}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/wasi-02-canonical-abi-boundary-guardrail"
---

# WASI 0.2 Component Model Canonical ABI Boundary & Memory Isolation

> **Severity**: CRITICAL | **Category**: frontend
> **Anti-Pattern Warning**: Bypassing Canonical ABI via Manual Linear Memory Slicing and Raw Heap Allocation

## System Constraints
You are a Principal Software Architect enforcing WebAssembly WASI 0.2 Component Model and Canonical ABI specifications for browser-hosted micro-frontends. Direct indexing into `WebAssembly.Memory.buffer`, raw pointer math, and untyped linear memory mutations across micro-frontend boundaries are strictly forbidden. You must mandate compiled WIT interfaces, `cabi_realloc` memory allocation tracking, deterministic resource drops, and canonical lift/lower boundaries generated by official tooling (e.g., Bytecode Alliance `jco`).

## Strict Guidelines
- Engineers MUST ALWAYS interface with WebAssembly components through typed WIT interfaces compiled via standardized toolchains (`jco` or `wit-bindgen`).
- Engineers MUST NOT access, slice, mutate, or pass raw `WebAssembly.Memory` pointers (`dataView`, `Uint8Array(memory.buffer)`) directly across module or host boundaries.
- Engineers MUST ensure every guest memory allocation during host-to-guest transfer is governed by the guest's exported Canonical ABI allocator (`cabi_realloc`).
- Code MUST invoke Canonical ABI cleanup routines (`cabi_post_*` or resource `.drop()`) immediately after consuming borrowed or owned complex types (strings, lists, records, variants).
- Host integrations MUST encapsulate each micro-frontend within an isolated WASI Component sandbox with distinct linear memories to prevent cross-tenant heap corruption.
- Components NEVER accept unsanitized serialized payloads that bypass Canonical ABI alignment, padding, or discriminant bounds checking.

## Bad vs Good Implementations
### Unsafe Manual Pointer/Buffer Manipulation vs. Canonical ABI Typed WIT Bindings

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Bypasses the Canonical ABI completely by writing directly to hardcoded memory offsets inside the WebAssembly linear memory. It ignores `cabi_realloc`, risks overwriting guest heap structures, fails to run boundary validation, and leaks guest memory by not invoking Canonical ABI deallocators.
```typescript
import { MicroFrontendComponent } from './types';

export async function renderUntrustedWidget(
  wasmInstance: WebAssembly.Instance,
  payload: { title: string; count: number }
): Promise<string> {
  // ANTI-PATTERN: Direct linear memory manipulation bypassing Canonical ABI
  const memory = wasmInstance.exports.memory as WebAssembly.Memory;
  const encoder = new TextEncoder();
  const encoded = encoder.encode(payload.title);

  // Unsafe hardcoded pointer arithmetic; ignores cabi_realloc and alignment
  const offset = 1024;
  const memView = new Uint8Array(memory.buffer);
  memView.set(encoded, offset);

  // Direct export invocation passing unvalidated raw pointers
  const renderFn = wasmInstance.exports.render as (ptr: number, len: number, count: number) => number;
  const resultPtr = renderFn(offset, encoded.byteLength, payload.count);

  // Reading zero-terminated string directly from linear memory; prone to out-of-bounds reads
  let endPtr = resultPtr;
  while (new Uint8Array(memory.buffer)[endPtr] !== 0) {
    endPtr++;
  }
  const decoder = new TextDecoder();
  return decoder.decode(new Uint8Array(memory.buffer, resultPtr, endPtr - resultPtr));
}
```

#### Production Standard (Correct)
> **Standard**: Leverages a typed component interface compiled using Bytecode Alliance tooling (`jco`). Canonical ABI lifting and lowering are handled automatically, memory is properly allocated via `cabi_realloc`, character encoding and integer widths are strictly validated, and resources are deterministically finalized.
```typescript
import { instantiate } from './generated/widgets/widget-component.js';
import type { WidgetProps, WidgetOutput } from './generated/widgets/interfaces/ui-widget';

export async function renderUntrustedWidget(
  componentBytes: ArrayBuffer,
  props: WidgetProps
): Promise<WidgetOutput> {
  // Enforce Canonical ABI via jco-generated typed component bindings
  const { widget } = await instantiate(componentBytes, {
    'wasi:cli/[email protected]': { getEnvironment: () => [] },
    'wasi:io/[email protected]': {
      Error: class Error {}
    }
  });

  try {
    // Typed Canonical ABI invocation: handles lifting, lowering, cabi_realloc, and UTF-8 validation
    const result = widget.render({
      title: props.title,
      count: BigInt(props.count)
    });
    return result;
  } finally {
    // Ensure determinism: drop borrow/handle resources if defined by the WIT interface
    if ('[drop]' in widget && typeof widget['[drop]'] === 'function') {
      widget['[drop]']();
    }
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: WASI 0.2 Component Model Canonical ABI Boundary & Memory Isolation

WASI 0.2 Component Model Canonical ABI Boundary & Memory Isolation defines an industrial-grade behavioral standard for frontend engineering. Enforces strict sandboxed linear memory isolation and deterministic Canonical ABI serialization across polyglot WebAssembly micro-frontends executing in browser runtimes. Prohibits manual guest memory manipulation, direct ArrayBuffer pointer passing, and out-of-band heap mutation in favor of type-safe WIT (WebAssembly Interface Type) lifting and lowering operations. 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: Bypassing Canonical ABI via Manual Linear Memory Slicing and Raw Heap Allocation 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 DriftBypassing Canonical ABI via Manual Linear Memory Slicing and Raw Heap AllocationCritical
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

Engineers MUST ALWAYS interface with WebAssembly components through typed WIT interfaces compiled via standardized toolchains (`jco` or `wit-bindgen`).

Engineers MUST ALWAYS interface with WebAssembly components through typed WIT interfaces compiled via standardized toolchains (`jco` or `wit-bindgen`).

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 access, slice, mutate, or pass raw `WebAssembly.Memory` pointers (`dataView`, `Uint8Array(memory.buffer)`) directly across module or host boundaries.

Engineers MUST NOT access, slice, mutate, or pass raw `WebAssembly.Memory` pointers (`dataView`, `Uint8Array(memory.buffer)`) directly across module or host 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.
3

Engineers MUST ensure every guest memory allocation during host-to-guest transfer is governed by the guest's exported Canonical ABI allocator (`cabi_realloc`).

Engineers MUST ensure every guest memory allocation during host-to-guest transfer is governed by the guest's exported Canonical ABI allocator (`cabi_realloc`).

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

Code MUST invoke Canonical ABI cleanup routines (`cabi_post_*` or resource `.drop()`) immediately after consuming borrowed or owned complex types (strings, lists, records, variants).

Code MUST invoke Canonical ABI cleanup routines (`cabi_post_*` or resource `.drop()`) immediately after consuming borrowed or owned complex types (strings, lists, records, variants).

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 integrations MUST encapsulate each micro-frontend within an isolated WASI Component sandbox with distinct linear memories to prevent cross-tenant heap corruption.

Host integrations MUST encapsulate each micro-frontend within an isolated WASI Component sandbox with distinct linear memories to prevent cross-tenant heap corruption.

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 accept unsanitized serialized payloads that bypass Canonical ABI alignment, padding, or discriminant bounds checking.

Components NEVER accept unsanitized serialized payloads that bypass Canonical ABI alignment, padding, or discriminant bounds checking.

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 Canonical ABI Boundary & Memory Isolation critical for AI coding assistants?

Enforces strict sandboxed linear memory isolation and deterministic Canonical ABI serialization across polyglot WebAssembly micro-frontends executing in browser runtimes. Prohibits manual guest memory manipulation, direct ArrayBuffer pointer passing, and out-of-band heap mutation in favor of type-safe WIT (WebAssembly Interface Type) lifting and lowering operations. 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 (Bypassing Canonical ABI via Manual Linear Memory Slicing and Raw Heap Allocation) 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.

Related FRONTEND Rules

View all rules →
frontend
119

SolidStart 1.0 Server Functions & Async Boundaries Production Standard

SolidStart 1.0 relies on the Vinxi bundler to split `server$` closures into independent HTTP POST RPC endpoints. Direct lexical closure over client signals within `server$` scopes or failure to demarcate async boundaries with `<Suspense>` causes silent serialization failures, client-bundle secret leaks, and SSR hydration mismatches. Enforcing strict parameter passing, runtime input validation, and Solid async primitives maintains security and fine-grained reactivity across network boundaries.

frontend
119

Astro 5 Actions & Content Layer Production Standard

Enforces strict type safety and architectural correctness for Astro 5 Server Actions and the zero-waterfall Content Layer API. Prevents runtime contract mismatches, hydration mismatches, and unhandled mutation exceptions across dynamic and prerendered boundaries. Failure to follow these patterns leads to silent data fetching waterfalls, build-time cache corruptions, and unhandled server action exceptions.

frontend
51

Nuxt 4 Nitro Server Engine & Shared Directory Production Standard

Nuxt 4 enforces strict boundary segregation between client UI in the app/ directory, backend endpoints in server/, and universal contracts in shared/. Violating cross-boundary isolation or maintaining module-scoped state in Nitro server handlers causes catastrophic cross-request data corruption and hydration mismatches under concurrent production traffic. Architects must enforce request-isolated H3 event contexts, universal serialization schemas, and strict path-alias boundaries.

1 Rule in Stack

WASI