This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: wasi-0-2-capability-sandbox-boundary

WASI 0.2 Component Model Capability-Based Sandbox Boundary Policy

Enforces strict deny-by-default capability boundaries for multi-tenant WebAssembly 0.2 component execution. Requires explicit capability attenuation, prohibiting ambient authority inheritance such as host environment, socket access, or unrestricted filesystem preopens in host runtimes. Mandates virtualized clocks, isolated store resource limits, and explicit outbound network proxies via WASI HTTP interfaces.

Prohibited Anti-Pattern: Ambient Host Resource Inheritance via Unrestricted WASI Preview 2 Host Context Linker

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WASI 0.2 Component Model Capability-Based Sandbox Boundary Policy - Enforces strict deny-by-default capability boundaries for multi-tenant WebAssembly 0.2 component execution. Requires explicit capability attenuation, prohibiting ambient authority inheritance such as host environment, socket access, or unrestricted filesystem preopens in host runtimes. Mandates virtualized clocks, isolated store resource limits, and explicit outbound network proxies via WASI HTTP interfaces.
globs: crates/**/src/**/*.rs, src/**/*.rs, host/**/*.rs, wit/**/*.wit
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/wasi-0-2-capability-sandbox-boundary"
---

# WASI 0.2 Component Model Capability-Based Sandbox Boundary Policy

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Ambient Host Resource Inheritance via Unrestricted WASI Preview 2 Host Context Linker

## System Constraints
You are a Principal Security Architect enforcing WASI 0.2 Component Model Capability-Based Sandbox Boundary Policies. Mandate strict capability attenuation: multi-tenant guest components must never inherit ambient host authority. All access to system clocks, filesystems, networking, environment variables, and random sources must be explicitly granted through isolated, virtualized capabilities and governed by store resource limiters.

## Strict Guidelines
- Engineers MUST ALWAYS instantiate WASI 0.2 contexts using explicit deny-by-default builders, omitting all forms of ambient inheritance (`inherit_stdio`, `inherit_env`, `inherit_network`).
- Engineers MUST NOT expose raw host directory paths or root mount points via `preopened_dir`; all filesystem access must be restricted to isolated scratch directories or ephemeral virtual in-memory filesystems with minimum necessary permissions (`DirPerms::READ`, `FilePerms::READ`).
- Code SHOULD implement `wasmtime::ResourceLimiter` or `Store::limiter` to constrain maximum memory growth, table elements, and fuel consumption for every multi-tenant guest instance.
- Services MUST route all outbound network requests (`wasi:http/outgoing-handler`) through an attenuated host proxy implementing strict tenant-level domain allowlisting and private IP (RFC 1918 / RFC 4193 / link-local) CIDR rejection.
- Components NEVER receive access to non-deterministic host system wall clocks; monotonic and wall clocks must be clamped or virtualized to prevent side-channel timing attacks.

## Bad vs Good Implementations
### WASI 0.2 Context Initialization & Capability Attenuation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Inheriting host stdio, environment variables, raw network access, and preopening the host root directory leaks host secrets, allows SSRF against internal services, and breaks guest tenant isolation entirely.
```rust
use wasmtime_wasi::WasiCtxBuilder;

pub fn setup_wasi_context() -> anyhow::Result<wasmtime_wasi::WasiCtx> {
    // DANGEROUS: Grants ambient access to host stdio, host environment, network, and root FS
    let ctx = WasiCtxBuilder::new()
        .inherit_stdio()
        .inherit_env()
        .inherit_network()
        .preopened_dir("/", "/", wasmtime_wasi::DirPerms::all(), wasmtime_wasi::FilePerms::all())?
        .build();
    Ok(ctx)
}
```

#### Production Standard (Correct)
> **Standard**: Creates a secure sandbox with zero ambient authority: stdout/stderr are isolated memory buffers, network/env access are rejected, and filesystem access is confined to a strictly scoped capability handle.
```rust
use wasmtime_wasi::pipe::MemoryOutputPipe;
use wasmtime_wasi::{DirPerms, FilePerms, WasiCtx, WasiCtxBuilder};
use cap_std::fs::Dir;

pub fn setup_wasi_context(
    isolated_scratch: Dir,
    tenant_stdout: MemoryOutputPipe,
    tenant_stderr: MemoryOutputPipe,
) -> anyhow::Result<WasiCtx> {
    // SECURE: Deny-by-default, piped virtual streams, isolated sandbox directory, no ambient host network
    let ctx = WasiCtxBuilder::new()
        .stdout(tenant_stdout)
        .stderr(tenant_stderr)
        .preopened_dir(
            isolated_scratch,
            DirPerms::READ | DirPerms::MUTATE,
            FilePerms::READ | FilePerms::WRITE,
            "/sandbox",
        )
        .build();
    Ok(ctx)
}
```

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: WASI 0.2 Component Model Capability-Based Sandbox Boundary Policy

WASI 0.2 Component Model Capability-Based Sandbox Boundary Policy defines an industrial-grade behavioral standard for security engineering. Enforces strict deny-by-default capability boundaries for multi-tenant WebAssembly 0.2 component execution. Requires explicit capability attenuation, prohibiting ambient authority inheritance such as host environment, socket access, or unrestricted filesystem preopens in host runtimes. Mandates virtualized clocks, isolated store resource limits, and explicit outbound network proxies via WASI HTTP interfaces. 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: Ambient Host Resource Inheritance via Unrestricted WASI Preview 2 Host Context Linker 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 DriftAmbient Host Resource Inheritance via Unrestricted WASI Preview 2 Host Context LinkerCritical
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 instantiate WASI 0.2 contexts using explicit deny-by-default builders, omitting all forms of ambient inheritance (`inherit_stdio`, `inherit_env`, `inherit_network`).

Engineers MUST ALWAYS instantiate WASI 0.2 contexts using explicit deny-by-default builders, omitting all forms of ambient inheritance (`inherit_stdio`, `inherit_env`, `inherit_network`).

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 expose raw host directory paths or root mount points via `preopened_dir`

Engineers MUST NOT expose raw host directory paths or root mount points via `preopened_dir`; all filesystem access must be restricted to isolated scratch directories or ephemeral virtual in-memory filesystems with minimum necessary permissions (`DirPerms::READ`, `FilePerms::READ`).

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

Code SHOULD implement `wasmtime

Code SHOULD implement `wasmtime::ResourceLimiter` or `Store::limiter` to constrain maximum memory growth, table elements, and fuel consumption for every multi-tenant guest 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.
4

Services MUST route all outbound network requests (`wasi

Services MUST route all outbound network requests (`wasi:http/outgoing-handler`) through an attenuated host proxy implementing strict tenant-level domain allowlisting and private IP (RFC 1918 / RFC 4193 / link-local) CIDR rejection.

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

Components NEVER receive access to non-deterministic host system wall clocks

Components NEVER receive access to non-deterministic host system wall clocks; monotonic and wall clocks must be clamped or virtualized to prevent side-channel timing attacks.

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 Capability-Based Sandbox Boundary Policy critical for AI coding assistants?

Enforces strict deny-by-default capability boundaries for multi-tenant WebAssembly 0.2 component execution. Requires explicit capability attenuation, prohibiting ambient authority inheritance such as host environment, socket access, or unrestricted filesystem preopens in host runtimes. Mandates virtualized clocks, isolated store resource limits, and explicit outbound network proxies via WASI HTTP interfaces. 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 (Ambient Host Resource Inheritance via Unrestricted WASI Preview 2 Host Context Linker) 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