This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: wasi-p2-socket-sandboxing-standard

WASI 0.2 Component Model Socket Sandboxing & Capability Attestation

Enforces compile-time-attested capability descriptors and link-time virtualization for multi-tenant serverless WebAssembly components. Mandates that guest components must never import raw WASI 0.2 `wasi:sockets` interfaces directly without cryptographic capability validation, ensuring network egress is constrained exclusively to host-brokered virtual resources.

Prohibited Anti-Pattern: Direct import or non-virtualized link-time binding of unconstrained wasi:sockets interfaces in multi-tenant WASI 0.2 components

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WASI 0.2 Component Model Socket Sandboxing & Capability Attestation - Enforces compile-time-attested capability descriptors and link-time virtualization for multi-tenant serverless WebAssembly components. Mandates that guest components must never import raw WASI 0.2 `wasi:sockets` interfaces directly without cryptographic capability validation, ensuring network egress is constrained exclusively to host-brokered virtual resources.
globs: wit/**/*.wit, src/**/*.rs, src/**/*.ts, Cargo.toml, wasm-tools.config.toml, **/wasi-runtime.config.{json,toml,yaml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/wasi-p2-socket-sandboxing-standard"
---

# WASI 0.2 Component Model Socket Sandboxing & Capability Attestation

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Direct import or non-virtualized link-time binding of unconstrained wasi:sockets interfaces in multi-tenant WASI 0.2 components

## System Constraints
You are a Principal Security Architect enforcing WASI 0.2 Component Model Socket Sandboxing. Multi-tenant WebAssembly guests must never access host TCP/UDP sockets directly. Mandate that all component WIT worlds omit raw `wasi:sockets/*` unless backed by an immutable link-time capability attestation token. Enforce host runtime adapter redirection using link-time virtualization or compile-time WIT capability scoping so that socket creation outside permitted host routing tables is physically unrepresentable.

## Strict Guidelines
- Components MUST NOT import raw `wasi:sockets/[email protected]` or `wasi:sockets/[email protected]` inside user-facing multi-tenant WIT worlds.
- Engineers MUST ALWAYS route all external egress through mediated virtual interfaces (such as `wasi:http/[email protected]` or a tenant-scoped broker world).
- Runtimes (Wasmtime, WasmEdge, Spin) MUST explicitly configure `WasiCtxBuilder::inherit_network()` to false and refuse instantiation when socket capabilities lack tenant-scoped cryptographic attestations.
- Link-time composition tools (e.g., `wac`, `wasm-tools compose`) MUST replace any unconstrained socket dependencies with virtualization shims that return `wasi:sockets/network/error-code::access-denied` for unauthorized endpoints.
- Component deployment manifests MUST declare explicit, immutable socket-binding policies that match runtime-attested capability manifests, verified at pre-flight CI/CD gates.

## Bad vs Good Implementations
### Wasmtime Host Runtime Instantiation with Denied Raw Sockets and Virtualized HTTP Egress

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using `inherit_network()` permits any guest component linking against `wasi:sockets` to open arbitrary TCP/UDP connections to internal infrastructure, breaking multi-tenant sandboxing.
```rust
// BAD: Host directly exposes inherited network sockets to untrusted guest
use wasmtime::component::Linker;
use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiView};

struct HostState {
    ctx: WasiCtx,
}

impl WasiView for HostState {
    fn ctx(&mut self) -> &mut WasiCtx { &mut self.ctx }
}

fn configure_runtime() -> HostState {
    let mut builder = WasiCtxBuilder::new();
    // Flaw: Unsandboxed socket exposure across all tenant components
    builder.inherit_network();
    HostState { ctx: builder.build() }
}
```

#### Production Standard (Correct)
> **Standard**: Raw network inheritance is omitted. Guest sockets cannot be instantiated, and any network activity must traverse attested, tenant-scoped host handler interfaces.
```rust
// GOOD: Host strips socket capabilities and provides zero-trust virtualized egress
use wasmtime::component::Linker;
use wasmtime_wasi::{WasiCtx, WasiCtxBuilder, WasiView, SocketError};

struct HostState {
    ctx: WasiCtx,
    tenant_id: String,
}

impl WasiView for HostState {
    fn ctx(&mut self) -> &mut WasiCtx { &mut self.ctx }
}

fn configure_runtime(tenant_id: &str) -> HostState {
    let mut builder = WasiCtxBuilder::new();
    // Invariant: Disallow arbitrary raw sockets; do not inherit network
    // Outgoing requests are constrained strictly to tenant-allowlisted virtual HTTP brokers
    HostState {
        ctx: builder.build(),
        tenant_id: tenant_id.to_string(),
    }
}
```

### WIT World Definition: Sandboxed Component vs Unconstrained Direct Socket Access

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly importing `wasi:sockets` gives the component raw socket primitive creation capabilities, completely bypassing host policy and application-layer access controls.
```wit
// BAD: Guest directly imports raw WASI sockets
package enterprise:[email protected];

world untrusted-guest {
    // Flaw: Unconstrained socket creation capability imported directly
    import wasi:sockets/[email protected];
    import wasi:sockets/[email protected];
    export wasi:http/[email protected];
}
```

#### Production Standard (Correct)
> **Standard**: Raw socket interfaces are completely eliminated from the component's WIT world. Communication is restricted to authorized high-level protocols mediated by the host.
```wit
// GOOD: World declares mediated, auditable egress without raw socket primitives
package enterprise:[email protected];

world secure-guest {
    // Invariant: Only declared virtualized application protocols are exposed
    import wasi:http/[email protected];
    import tenant:attestation/[email protected];
    
    export wasi:http/[email protected];
}
```

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 Socket Sandboxing & Capability Attestation

WASI 0.2 Component Model Socket Sandboxing & Capability Attestation defines an industrial-grade behavioral standard for devops engineering. Enforces compile-time-attested capability descriptors and link-time virtualization for multi-tenant serverless WebAssembly components. Mandates that guest components must never import raw WASI 0.2 `wasi:sockets` interfaces directly without cryptographic capability validation, ensuring network egress is constrained exclusively to host-brokered virtual resources. 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: Direct import or non-virtualized link-time binding of unconstrained wasi:sockets interfaces in multi-tenant WASI 0.2 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 DriftDirect import or non-virtualized link-time binding of unconstrained wasi:sockets interfaces in multi-tenant WASI 0.2 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 NOT import raw `wasi

Components MUST NOT import raw `wasi:sockets/[email protected]` or `wasi:sockets/[email protected]` inside user-facing multi-tenant WIT worlds.

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 ALWAYS route all external egress through mediated virtual interfaces (such as `wasi

Engineers MUST ALWAYS route all external egress through mediated virtual interfaces (such as `wasi:http/[email protected]` or a tenant-scoped broker world).

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

Runtimes (Wasmtime, WasmEdge, Spin) MUST explicitly configure `WasiCtxBuilder

Runtimes (Wasmtime, WasmEdge, Spin) MUST explicitly configure `WasiCtxBuilder::inherit_network()` to false and refuse instantiation when socket capabilities lack tenant-scoped cryptographic attestations.

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

Link-time composition tools (e.g., `wac`, `wasm-tools compose`) MUST replace any unconstrained socket dependencies with virtualization shims that return `wasi

Link-time composition tools (e.g., `wac`, `wasm-tools compose`) MUST replace any unconstrained socket dependencies with virtualization shims that return `wasi:sockets/network/error-code::access-denied` for unauthorized endpoints.

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

Component deployment manifests MUST declare explicit, immutable socket-binding policies that match runtime-attested capability manifests, verified at pre-flight CI/CD gates.

Component deployment manifests MUST declare explicit, immutable socket-binding policies that match runtime-attested capability manifests, verified at pre-flight CI/CD gates.

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 Socket Sandboxing & Capability Attestation critical for AI coding assistants?

Enforces compile-time-attested capability descriptors and link-time virtualization for multi-tenant serverless WebAssembly components. Mandates that guest components must never import raw WASI 0.2 `wasi:sockets` interfaces directly without cryptographic capability validation, ensuring network egress is constrained exclusively to host-brokered virtual resources. 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 (Direct import or non-virtualized link-time binding of unconstrained wasi:sockets interfaces in multi-tenant WASI 0.2 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