This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: k8s-gateway-api-wasm-sandbox-circuit-breaker

Kubernetes Gateway API Wasm Sandbox Memory Bounds and Host-Call Circuit Breaker

Enforces strict linear memory limits, deterministic execution deadlines, and host-call circuit breakers for Envoy WebAssembly (Wasm) filters deployed via Kubernetes Gateway API extensions. Prevents rogue Wasm plugins from crashing data-plane worker threads, starving host memory pools, or destabilizing ingress edge proxies during runtime faults.

Prohibited Anti-Pattern: Deploying Unbounded Wasm Plugins with Fail-Closed Policies and Blocking Host Calls

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Gateway API Wasm Sandbox Memory Bounds and Host-Call Circuit Breaker - Enforces strict linear memory limits, deterministic execution deadlines, and host-call circuit breakers for Envoy WebAssembly (Wasm) filters deployed via Kubernetes Gateway API extensions. Prevents rogue Wasm plugins from crashing data-plane worker threads, starving host memory pools, or destabilizing ingress edge proxies during runtime faults.
globs: **/k8s/**/*.yaml, **/gateway/**/*.yaml, **/envoy-extension-policy.yaml, **/wasmplugin*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-gateway-api-wasm-sandbox-circuit-breaker"
---

# Kubernetes Gateway API Wasm Sandbox Memory Bounds and Host-Call Circuit Breaker

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Deploying Unbounded Wasm Plugins with Fail-Closed Policies and Blocking Host Calls

## System Constraints
You are a Principal Platform and Edge Proxy Architect enforcing deterministic execution bounds and memory sandboxing for WebAssembly (Wasm) extensions on Kubernetes Gateway API. All data-plane extensions must guarantee that worker threads cannot be starved or crashed by untrusted or failing Wasm guest modules.

## Strict Guidelines
- Engineers MUST ALWAYS configure explicit linear memory allocation caps (e.g., `max_number_of_pages`) for the Wasm runtime VM.
- Engineers MUST ALWAYS declare `fail_open: true` for non-critical edge Wasm plugins to prevent traffic blackholing on panic or VM traps.
- Engineers MUST configure explicit call deadlines (sub-50ms) and consecutive failure thresholds for out-of-process Wasm host calls (`proxy_wasm_dispatch_http_call`).
- Engineers MUST NOT allow Wasm filters to consume dynamic memory without bounding the maximum internal buffer sizes on HTTP stream callbacks.
- Policies MUST define isolated VM runtimes (`vm_id`) per tenant or domain to prevent a single guest runtime fault from corrupting shared data-plane memory.

## Bad vs Good Implementations
### Kubernetes EnvoyExtensionPolicy Wasm Filter Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The extension lacks memory bounds, timeouts, and fallback configurations. If the Wasm plugin leaks memory or hangs during external HTTP host dispatch, Envoy worker threads will encounter fatal traps or OOM panics, blackholing all downstream ingress traffic.
```yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
  name: auth-wasm-filter
  namespace: ingress-system
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: api-route
  wasm:
    - name: edge-auth
      code:
        http:
          url: https://registry.internal.net/wasm/auth:v1.2.0
      # ANTI-PATTERN: Default VM settings with unbounded memory, 
      # no fail_open strategy, and no host-call execution limits.
      failOpen: false
```

#### Production Standard (Correct)
> **Standard**: Defines an isolated VM namespace, strictly bounds the WebAssembly memory allocation to 32 MiB (512 64KiB pages), enforces a 25ms host-call timeout with circuit breaking, and sets `failOpen: true` to preserve edge proxy availability.
```yaml
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
  name: auth-wasm-filter
  namespace: ingress-system
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: api-route
  wasm:
    - name: edge-auth
      failOpen: true
      code:
        http:
          url: https://registry.internal.net/wasm/auth:v1.2.0
          sha256: 4b227777d4dd1fc61c6f884f48641d02b4d121d3fd328cb08b5531fcacdabf8a
      vmConfig:
        runtime: envoy.wasm.runtime.v8
        vmId: tenant_auth_isolated_vm
        configuration:
          max_memory_pages: 512 # 32 MiB linear memory limit
          host_call_timeout_ms: 25
          circuit_breaker:
            consecutive_errors: 5
            recovery_timeout_sec: 30
```

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: Kubernetes Gateway API Wasm Sandbox Memory Bounds and Host-Call Circuit Breaker

Kubernetes Gateway API Wasm Sandbox Memory Bounds and Host-Call Circuit Breaker defines an industrial-grade behavioral standard for devops engineering. Enforces strict linear memory limits, deterministic execution deadlines, and host-call circuit breakers for Envoy WebAssembly (Wasm) filters deployed via Kubernetes Gateway API extensions. Prevents rogue Wasm plugins from crashing data-plane worker threads, starving host memory pools, or destabilizing ingress edge proxies during runtime faults. 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: Deploying Unbounded Wasm Plugins with Fail-Closed Policies and Blocking Host Calls 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 DriftDeploying Unbounded Wasm Plugins with Fail-Closed Policies and Blocking Host CallsCritical
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 configure explicit linear memory allocation caps (e.g., `max_number_of_pages`) for the Wasm runtime VM.

Engineers MUST ALWAYS configure explicit linear memory allocation caps (e.g., `max_number_of_pages`) for the Wasm runtime VM.

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 declare `fail_open

Engineers MUST ALWAYS declare `fail_open: true` for non-critical edge Wasm plugins to prevent traffic blackholing on panic or VM traps.

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 configure explicit call deadlines (sub-50ms) and consecutive failure thresholds for out-of-process Wasm host calls (`proxy_wasm_dispatch_http_call`).

Engineers MUST configure explicit call deadlines (sub-50ms) and consecutive failure thresholds for out-of-process Wasm host calls (`proxy_wasm_dispatch_http_call`).

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

Engineers MUST NOT allow Wasm filters to consume dynamic memory without bounding the maximum internal buffer sizes on HTTP stream callbacks.

Engineers MUST NOT allow Wasm filters to consume dynamic memory without bounding the maximum internal buffer sizes on HTTP stream callbacks.

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

Policies MUST define isolated VM runtimes (`vm_id`) per tenant or domain to prevent a single guest runtime fault from corrupting shared data-plane memory.

Policies MUST define isolated VM runtimes (`vm_id`) per tenant or domain to prevent a single guest runtime fault from corrupting shared data-plane memory.

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 Kubernetes Gateway API Wasm Sandbox Memory Bounds and Host-Call Circuit Breaker critical for AI coding assistants?

Enforces strict linear memory limits, deterministic execution deadlines, and host-call circuit breakers for Envoy WebAssembly (Wasm) filters deployed via Kubernetes Gateway API extensions. Prevents rogue Wasm plugins from crashing data-plane worker threads, starving host memory pools, or destabilizing ingress edge proxies during runtime faults. 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 (Deploying Unbounded Wasm Plugins with Fail-Closed Policies and Blocking Host Calls) 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

Kubernetes