This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
backendcritical PriorityID: wasi-component-memory-quota-boundary

Deterministic Linear Memory Quotas and Capability Boundaries for WASI 0.2

Multi-tenant WASI 0.2 component execution requires explicit linear memory limits, pooled allocation limits, and non-blocking capability interfaces. Without strict host-enforced memory ceilings and deadman timers, untrusted guest components can induce host Out-Of-Memory (OOM) crashes and thread starvation through unmetered memory expansion.

Prohibited Anti-Pattern: Unbounded Linear Memory Growth and Blocking Capability Execution in Multi-Tenant Component Runtimes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Deterministic Linear Memory Quotas and Capability Boundaries for WASI 0.2 - Multi-tenant WASI 0.2 component execution requires explicit linear memory limits, pooled allocation limits, and non-blocking capability interfaces. Without strict host-enforced memory ceilings and deadman timers, untrusted guest components can induce host Out-Of-Memory (OOM) crashes and thread starvation through unmetered memory expansion.
globs: src/plugins/**/*.{ts,tsx,rs}, src/runtime/**/*.{ts,tsx,rs}, wit/**/*.wit
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/wasi-component-memory-quota-boundary"
---

# Deterministic Linear Memory Quotas and Capability Boundaries for WASI 0.2

> **Severity**: CRITICAL | **Category**: backend
> **Anti-Pattern Warning**: Unbounded Linear Memory Growth and Blocking Capability Execution in Multi-Tenant Component Runtimes

## System Constraints
You are a Principal Systems Architect enforcing WASI 0.2 Component Model Sandboxed Memory Quota Boundaries. Multi-tenant dynamic plugin executions must strictly operate within isolated, pre-metered linear memory partitions and non-blocking asynchronous capability interfaces to prevent host starvation.

## Strict Guidelines
- Engineers MUST ALWAYS enforce strict maximum linear memory page limits (`ResourceLimiter::memory_growing` / max 64KiB WebAssembly page quotas) per component store instance.
- Engineers MUST NOT allow unmetered `memory.grow` instructions or instantiate guest instances with unbounded `WebAssembly.Memory` limits.
- Services MUST configure epoch-based interruption or fuel metering for host runtimes to prevent guest compute stalls and infinite dynamic allocation loops.
- Components NEVER expose synchronous, blocking I/O calls to guest plugins; all capability host imports must leverage WASI 0.2 non-blocking pollable handles (`wasi:io/poll.pollable`).
- Code SHOULD pre-allocate virtual memory address spaces using pooled allocators to guarantee deterministic host memory ceilings across concurrent tenant executions.
- Services MUST immediately terminate and quarantine guest instances that trigger out-of-quota traps, preventing memory leakage into subsequent invocations.

## Bad vs Good Implementations
### Configuring WASI 0.2 Host Runtime with Strict Memory Ceiling and Non-Blocking Capabilities

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The host instantiates a guest module with no maximum page bounds on WebAssembly.Memory, allows unrestricted memory.grow operations, lacks fuel/epoch timeouts, and provides blocking synchronous capabilities that expose the host thread pool to exhaustion.
```typescript
import { readFile } from 'node:fs/promises';

// ANTI-PATTERN: Loading and instantiating WASI component with unbounded host memory
// and synchronous blocking capabilities, allowing guest to exhaust host resources.
export async function executePlugin(wasmPath: string, inputData: Uint8Array): Promise<Uint8Array> {
  const bytes = await readFile(wasmPath);
  // Unbounded memory allocation allows malicious guest to call memory.grow infinitely
  const memory = new WebAssembly.Memory({ initial: 10 });
  
  const hostCapabilities = {
    'wasi:cli/environment': { get_environment: () => [] },
    // Blocking synchronous file access exposed directly to sandboxed tenant
    'wasi:filesystem/types': {
      read_sync: (fd: number, len: number) => new Uint8Array(len)
    }
  };

  const { instance } = await WebAssembly.instantiate(bytes, {
    env: { memory },
    ...hostCapabilities
  });

  const run = instance.exports['run'] as (input: Uint8Array) => Uint8Array;
  return run(inputData);
}
```

#### Production Standard (Correct)
> **Standard**: The instance explicitly sets a deterministic upper memory page ceiling (`maximum: limits.maxPages`), mounts non-blocking capability handles complying with WASI 0.2 semantics, and enforces an execution timer to protect the host runtime from tenant resource exhaustion.
```typescript
import { readFile } from 'node:fs/promises';

interface MemoryLimiterConfig {
  maxPages: number; // 64 KiB per page
  timeoutMs: number;
}

const DEFAULT_LIMITS: MemoryLimiterConfig = {
  maxPages: 256, // Strict 16 MiB ceiling
  timeoutMs: 3000
};

// PRODUCTION-GRADE: Enforces bounded memory allocation, execution timeout, and non-blocking pollable interfaces
export async function executePluginDeterministic(
  wasmPath: string,
  inputData: Uint8Array,
  limits: MemoryLimiterConfig = DEFAULT_LIMITS
): Promise<Uint8Array> {
  const bytes = await readFile(wasmPath);

  // Strict upper bound prevents guest memory.grow beyond quota
  const memory = new WebAssembly.Memory({
    initial: 16,        // 1 MiB
    maximum: limits.maxPages
  });

  const abortController = new AbortController();
  const timeoutId = setTimeout(() => abortController.abort(new Error('Memory/Execution Timeout Exceeded')), limits.timeoutMs);

  try {
    const hostCapabilities = {
      'wasi:io/poll': {
        // WASI 0.2 async non-blocking pollable handle implementation
        poll_one: async (pollableId: number): Promise<boolean> => {
          if (abortController.signal.aborted) throw new Error('Host aborted execution');
          return Promise.resolve(true);
        }
      }
    };

    const module = await WebAssembly.compile(bytes);
    const instance = await WebAssembly.instantiate(module, {
      env: { memory },
      ...hostCapabilities
    });

    const run = instance.exports['run'] as (input: Uint8Array) => Uint8Array;
    return run(inputData);
  } finally {
    clearTimeout(timeoutId);
  }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Deterministic Linear Memory Quotas and Capability Boundaries for WASI 0.2

Deterministic Linear Memory Quotas and Capability Boundaries for WASI 0.2 defines an industrial-grade behavioral standard for backend engineering. Multi-tenant WASI 0.2 component execution requires explicit linear memory limits, pooled allocation limits, and non-blocking capability interfaces. Without strict host-enforced memory ceilings and deadman timers, untrusted guest components can induce host Out-Of-Memory (OOM) crashes and thread starvation through unmetered memory expansion. 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: Unbounded Linear Memory Growth and Blocking Capability Execution in Multi-Tenant Component Runtimes 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 DriftUnbounded Linear Memory Growth and Blocking Capability Execution in Multi-Tenant Component RuntimesCritical
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 enforce strict maximum linear memory page limits (`ResourceLimiter

Engineers MUST ALWAYS enforce strict maximum linear memory page limits (`ResourceLimiter::memory_growing` / max 64KiB WebAssembly page quotas) per component store instance.

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 allow unmetered `memory.grow` instructions or instantiate guest instances with unbounded `WebAssembly.Memory` limits.

Engineers MUST NOT allow unmetered `memory.grow` instructions or instantiate guest instances with unbounded `WebAssembly.Memory` limits.

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

Services MUST configure epoch-based interruption or fuel metering for host runtimes to prevent guest compute stalls and infinite dynamic allocation loops.

Services MUST configure epoch-based interruption or fuel metering for host runtimes to prevent guest compute stalls and infinite dynamic allocation 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.
4

Components NEVER expose synchronous, blocking I/O calls to guest plugins

Components NEVER expose synchronous, blocking I/O calls to guest plugins; all capability host imports must leverage WASI 0.2 non-blocking pollable handles (`wasi:io/poll.pollable`).

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

Code SHOULD pre-allocate virtual memory address spaces using pooled allocators to guarantee deterministic host memory ceilings across concurrent tenant executions.

Code SHOULD pre-allocate virtual memory address spaces using pooled allocators to guarantee deterministic host memory ceilings across concurrent tenant executions.

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

Services MUST immediately terminate and quarantine guest instances that trigger out-of-quota traps, preventing memory leakage into subsequent invocations.

Services MUST immediately terminate and quarantine guest instances that trigger out-of-quota traps, preventing memory leakage into subsequent invocations.

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 Deterministic Linear Memory Quotas and Capability Boundaries for WASI 0.2 critical for AI coding assistants?

Multi-tenant WASI 0.2 component execution requires explicit linear memory limits, pooled allocation limits, and non-blocking capability interfaces. Without strict host-enforced memory ceilings and deadman timers, untrusted guest components can induce host Out-Of-Memory (OOM) crashes and thread starvation through unmetered memory expansion. 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 (Unbounded Linear Memory Growth and Blocking Capability Execution in Multi-Tenant Component Runtimes) 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

Deterministic