This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: envoy-gateway-proxy-wasm-linear-memory-budgeting-guardrail

Envoy Gateway Proxy-Wasm Linear Memory Budgeting and Runtime Recycling Guardrail

Enforces strict WebAssembly (Wasm) linear memory limits, max page allocations, and instance lifecycle recycling across Envoy Gateway extension filters. Unbounded Wasm linear memory growth triggers OS-level OOM kills of shared Envoy worker threads, inducing cascading ingress failures across co-located tenants.

Prohibited Anti-Pattern: Unbounded Wasm Linear Memory and Indefinite VM Lifecycles Causing Worker Thread Crashes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Envoy Gateway Proxy-Wasm Linear Memory Budgeting and Runtime Recycling Guardrail - Enforces strict WebAssembly (Wasm) linear memory limits, max page allocations, and instance lifecycle recycling across Envoy Gateway extension filters. Unbounded Wasm linear memory growth triggers OS-level OOM kills of shared Envoy worker threads, inducing cascading ingress failures across co-located tenants.
globs: **/envoy-gateway/**/*.yaml, **/envoyextensionpolicy*.yaml, **/envoyfilter*.yaml, **/k8s/**/*.yaml, **/helm/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/envoy-gateway-proxy-wasm-linear-memory-budgeting-guardrail"
---

# Envoy Gateway Proxy-Wasm Linear Memory Budgeting and Runtime Recycling Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Unbounded Wasm Linear Memory and Indefinite VM Lifecycles Causing Worker Thread Crashes

## System Constraints
You are a Principal Engineer enforcing Envoy Gateway Proxy-Wasm Linear Memory Budgeting Guardrails. WebAssembly guest modules compile to linear 64KiB memory pages that dynamically grow via memory.grow instructions. In Envoy's multi-threaded event-driven architecture, an unconstrained Proxy-Wasm filter that experiences memory leaks or unbounded payload buffering will trigger host OOM aborts, terminating the Envoy worker thread and dropping all active TCP streams. You must mandate deterministic memory boundaries, fail-open/fail-closed error isolation, and strict VM lifecycle limits in all EnvoyExtensionPolicy and EnvoyFilter definitions.

## Strict Guidelines
- Engineers MUST ALWAYS declare explicit linear memory upper bounds using runtime engine constraints or proxy-wasm memory page ceilings (maximum 512 pages / 32 MiB per VM instance).
- Engineers MUST NOT deploy Wasm filters with shared VM contexts (shared runtime) without per-request allocation watermarks and strict buffer limits.
- Engineers MUST configure `fail_open: true` on observability/telemetry Wasm filters so guest runtime traps or memory exhaustion do not sever client ingress traffic.
- Engineers MUST configure `fail_open: false` with deterministic error responses (HTTP 500/503) exclusively on security-critical Wasm filters (e.g., auth, token verification, body inspection).
- Services MUST enable Envoy Wasm VM recycling or request-count limits when using heap-allocating languages (such as Rust or Go/TinyGo) to prevent progressive fragmentation.
- Components NEVER buffer unbounded request or response bodies inside Wasm linear memory; maximum streaming chunk sizes MUST be budgeted before buffering headers or payload.

## Bad vs Good Implementations
### EnvoyExtensionPolicy Wasm Memory Cap and Failure Mode Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The Wasm filter definition omits memory limits and failure domain isolation. If the guest module executes dynamic allocations without bounds (e.g., buffering a multi-megabyte payload), the linear memory expansion will exceed the process memory ceiling and trigger an immediate Envoy worker crash, dropping all co-located tenant streams.
```yaml
# INSECURE: Default unbounded Wasm VM with no memory budgeting or fail-safe isolation
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
  name: noisy-tenant-wasm-filter
  namespace: ingress-gateway
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: api-ingress-route
  wasm:
    - name: request-transformer
      code:
        type: HTTP
        http:
          url: https://internal-registry.corp/filters/transformer-v1.wasm
      # Anti-pattern: Missing fail_open configuration
      # Anti-pattern: Missing vm_config bounds and max memory limits
      # Result: Memory leak in guest Wasm crashes Envoy worker thread via host SIGABRT
```

#### Production Standard (Correct)
> **Standard**: The configuration specifies failOpen: true to isolate non-critical filter faults from terminating production traffic, pins the artifact via sha256, and budgets linear memory by passing strict page allocations (512 pages = 32 MiB) alongside a bounded buffer and lifecycle request recycling target.
```yaml
# SECURE: Hard memory-budgeted Wasm VM with explicit fail-open isolation and recycling
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyExtensionPolicy
metadata:
  name: bounded-tenant-wasm-filter
  namespace: ingress-gateway
spec:
  targetRef:
    group: gateway.networking.k8s.io
    kind: HTTPRoute
    name: api-ingress-route
  wasm:
    - name: request-transformer
      failOpen: true
      code:
        type: HTTP
        http:
          url: https://internal-registry.corp/filters/transformer-v1.wasm
          sha256: 9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
      config:
        "@type": type.googleapis.com/google.protobuf.StringValue
        value: |-
          {
            "max_buffer_bytes": 1048576,
            "max_memory_pages": 512,
            "recycle_after_requests": 100000
          }
```

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: Envoy Gateway Proxy-Wasm Linear Memory Budgeting and Runtime Recycling Guardrail

Envoy Gateway Proxy-Wasm Linear Memory Budgeting and Runtime Recycling Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces strict WebAssembly (Wasm) linear memory limits, max page allocations, and instance lifecycle recycling across Envoy Gateway extension filters. Unbounded Wasm linear memory growth triggers OS-level OOM kills of shared Envoy worker threads, inducing cascading ingress failures across co-located tenants. 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 Wasm Linear Memory and Indefinite VM Lifecycles Causing Worker Thread Crashes 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 Wasm Linear Memory and Indefinite VM Lifecycles Causing Worker Thread CrashesCritical
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 declare explicit linear memory upper bounds using runtime engine constraints or proxy-wasm memory page ceilings (maximum 512 pages / 32 MiB per VM instance).

Engineers MUST ALWAYS declare explicit linear memory upper bounds using runtime engine constraints or proxy-wasm memory page ceilings (maximum 512 pages / 32 MiB per VM 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 deploy Wasm filters with shared VM contexts (shared runtime) without per-request allocation watermarks and strict buffer limits.

Engineers MUST NOT deploy Wasm filters with shared VM contexts (shared runtime) without per-request allocation watermarks and strict buffer 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

Engineers MUST configure `fail_open

Engineers MUST configure `fail_open: true` on observability/telemetry Wasm filters so guest runtime traps or memory exhaustion do not sever client ingress traffic.

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

Engineers MUST configure `fail_open: false` with deterministic error responses (HTTP 500/503) exclusively on security-critical Wasm filters (e.g., auth, token verification, body inspection).

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

Services MUST enable Envoy Wasm VM recycling or request-count limits when using heap-allocating languages (such as Rust or Go/TinyGo) to prevent progressive fragmentation.

Services MUST enable Envoy Wasm VM recycling or request-count limits when using heap-allocating languages (such as Rust or Go/TinyGo) to prevent progressive fragmentation.

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 buffer unbounded request or response bodies inside Wasm linear memory

Components NEVER buffer unbounded request or response bodies inside Wasm linear memory; maximum streaming chunk sizes MUST be budgeted before buffering headers or payload.

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 Envoy Gateway Proxy-Wasm Linear Memory Budgeting and Runtime Recycling Guardrail critical for AI coding assistants?

Enforces strict WebAssembly (Wasm) linear memory limits, max page allocations, and instance lifecycle recycling across Envoy Gateway extension filters. Unbounded Wasm linear memory growth triggers OS-level OOM kills of shared Envoy worker threads, inducing cascading ingress failures across co-located tenants. 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 Wasm Linear Memory and Indefinite VM Lifecycles Causing Worker Thread Crashes) 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

Envoy