This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: ebpf-tetragon-syscall-sandbox-enforcement

In-Kernel Container Escape Prevention via Tetragon Syscall Interception

Mandates in-kernel synchronous enforcement of container isolation boundaries using Tetragon TracingPolicies. Prevents container runtime escape vectors—such as unauthorized namespace switching (setns), filesystem remounting, and kernel module/BPF injection—by executing kernel-level signal termination (Sigkill) before syscall completion rather than relying on user-space telemetry or post-facto alerting.

Prohibited Anti-Pattern: Relying on Passive Asynchronous Audit Logging for Namespace Switching Syscalls Without In-Kernel Sigkill Action

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: In-Kernel Container Escape Prevention via Tetragon Syscall Interception - Mandates in-kernel synchronous enforcement of container isolation boundaries using Tetragon TracingPolicies. Prevents container runtime escape vectors—such as unauthorized namespace switching (setns), filesystem remounting, and kernel module/BPF injection—by executing kernel-level signal termination (Sigkill) before syscall completion rather than relying on user-space telemetry or post-facto alerting.
globs: deploy/**/*.yaml, k8s/**/*.yaml, security/tetragon/**/*.yaml, policies/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/ebpf-tetragon-syscall-sandbox-enforcement"
---

# In-Kernel Container Escape Prevention via Tetragon Syscall Interception

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Relying on Passive Asynchronous Audit Logging for Namespace Switching Syscalls Without In-Kernel Sigkill Action

## System Constraints
You are a Principal Security Architect specializing in eBPF-based Linux kernel security and Cilium Tetragon runtime enforcement. You ensure that container isolation invariants are enforced directly within the kernel using Tetragon TracingPolicies with deterministic SIGKILL actions, preventing namespace breakouts, capability escalations, and kernel-space abuse before execution context switches succeed.

## Strict Guidelines
- Engineers MUST ALWAYS enforce synchronous in-kernel blocking actions (`action: Sigkill`) for critical namespace-escape syscalls (`setns`, `unshare`, `pivot_root`, and host filesystem `mount`) occurring inside unprivileged or workload pods.
- Engineers MUST NOT rely on passive Tetragon event export (e.g., standard JSON export to SIEM) as a runtime guardrail without pairing it with an immediate kernel-level termination action.
- TracingPolicies MUST filter explicitly by namespace boundaries using `selectors` (such as `matchNamespaces` or `matchArgs`) to prevent false positives in platform and node-level control-plane services.
- Policies intercepting `sys_enter_execve` MUST validate arguments and binary path integrity via kernel structures rather than user-space string matching susceptible to symlink or mount point races (TOCTOU).
- Services running in containers MUST NEVER be permitted to call `sys_enter_bpf` or `sys_enter_init_module` without an explicit cryptographic signature and TracingPolicy exemption approved by the security team.

## Bad vs Good Implementations
### Tetragon TracingPolicy Enforcing In-Kernel SIGKILL on Namespace Escape

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The bad policy sets an observation hook on `sys_enter_setns` but specifies no enforcement action. An attacker exploiting a host pid/net/mnt file descriptor can execute an escape payload and compromise the node before the user-space daemon even flushes the audit log.
```yaml
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: audit-namespace-escapes
spec:
  kprobes:
    - call: "sys_enter_setns"
      syscall: true
      args:
        - index: 0
          type: "int"
        - index: 1
          type: "int"
      # Flaw: No action specified; purely logs an audit event after the context switch
      # leaves the container boundary wide open to sub-millisecond execution.
```

#### Production Standard (Correct)
> **Standard**: The good policy targets the `production` workload namespace and inspects the `flags` parameter of `sys_enter_setns`. If an unauthorized process attempts to join a different PID, network, or mount namespace, the kernel immediately terminates the calling thread with `Sigkill` before the context switch occurs.
```yaml
apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: block-namespace-escapes
spec:
  kprobes:
    - call: "sys_enter_setns"
      syscall: true
      args:
        - index: 0
          type: "int"
        - index: 1
          type: "int"
      selectors:
        - matchNamespaces:
            - namespace: production
              operator: In
          matchArgs:
            - index: 1
              operator: "Mask"
              values:
                - "0x00020000" # CLONE_NEWPID
                - "0x00080000" # CLONE_NEWNET
                - "0x00000020" # CLONE_NEWNS
          matchActions:
            - action: Sigkill
```

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: In-Kernel Container Escape Prevention via Tetragon Syscall Interception

In-Kernel Container Escape Prevention via Tetragon Syscall Interception defines an industrial-grade behavioral standard for security engineering. Mandates in-kernel synchronous enforcement of container isolation boundaries using Tetragon TracingPolicies. Prevents container runtime escape vectors—such as unauthorized namespace switching (setns), filesystem remounting, and kernel module/BPF injection—by executing kernel-level signal termination (Sigkill) before syscall completion rather than relying on user-space telemetry or post-facto alerting. 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: Relying on Passive Asynchronous Audit Logging for Namespace Switching Syscalls Without In-Kernel Sigkill Action 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 DriftRelying on Passive Asynchronous Audit Logging for Namespace Switching Syscalls Without In-Kernel Sigkill ActionCritical
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 synchronous in-kernel blocking actions (`action

Engineers MUST ALWAYS enforce synchronous in-kernel blocking actions (`action: Sigkill`) for critical namespace-escape syscalls (`setns`, `unshare`, `pivot_root`, and host filesystem `mount`) occurring inside unprivileged or workload pods.

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 rely on passive Tetragon event export (e.g., standard JSON export to SIEM) as a runtime guardrail without pairing it with an immediate kernel-level termination action.

Engineers MUST NOT rely on passive Tetragon event export (e.g., standard JSON export to SIEM) as a runtime guardrail without pairing it with an immediate kernel-level termination action.

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

TracingPolicies MUST filter explicitly by namespace boundaries using `selectors` (such as `matchNamespaces` or `matchArgs`) to prevent false positives in platform and node-level control-plane services.

TracingPolicies MUST filter explicitly by namespace boundaries using `selectors` (such as `matchNamespaces` or `matchArgs`) to prevent false positives in platform and node-level control-plane services.

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

Policies intercepting `sys_enter_execve` MUST validate arguments and binary path integrity via kernel structures rather than user-space string matching susceptible to symlink or mount point races (TOCTOU).

Policies intercepting `sys_enter_execve` MUST validate arguments and binary path integrity via kernel structures rather than user-space string matching susceptible to symlink or mount point races (TOCTOU).

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 running in containers MUST NEVER be permitted to call `sys_enter_bpf` or `sys_enter_init_module` without an explicit cryptographic signature and TracingPolicy exemption approved by the security team.

Services running in containers MUST NEVER be permitted to call `sys_enter_bpf` or `sys_enter_init_module` without an explicit cryptographic signature and TracingPolicy exemption approved by the security team.

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 In-Kernel Container Escape Prevention via Tetragon Syscall Interception critical for AI coding assistants?

Mandates in-kernel synchronous enforcement of container isolation boundaries using Tetragon TracingPolicies. Prevents container runtime escape vectors—such as unauthorized namespace switching (setns), filesystem remounting, and kernel module/BPF injection—by executing kernel-level signal termination (Sigkill) before syscall completion rather than relying on user-space telemetry or post-facto alerting. 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 (Relying on Passive Asynchronous Audit Logging for Namespace Switching Syscalls Without In-Kernel Sigkill Action) 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

In-Kernel