crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[FEATURE]Architecture Proposal: Hardened Fallback Sandbox via VAREK AST Engine (CVE-2026-2287 Mitigation)

Open kwdoug63 opened this issue 7 months ago • 9 comments

Update (2026-04-20): Architecture superseded — see v1.1

The PEP 578 audit-hook design described below was the v1.0 architecture and has been superseded. External review (llamastack/llama-stack-apps#223) demonstrated that sys.addaudithook does not cross the subprocess boundary — the hook fires only in the current interpreter, so a child process spawned via subprocess.run executes outside the hook's visibility. The accompanying string-signature denylist was also unsound against renamed binaries, absolute paths, and encoded payloads.

VAREK v1.1 (shipped 2026-04-20) moves enforcement off the interpreter hook and into the kernel:

  • seccomp-bpf` filter loaded under PR_SET_NO_NEW_PRIVS so it is inherited across every fork/clone and cannot be dropped
  • cgroups v2 for memory / cpu / pids / wall-clock bounds
  • user / mount / network / IPC / PID namespaces execve denied by default in the sandbox, which makes the binary allowlist trivially enforceable at the parent
  • PEP 578 hook retained as telemetry only; it no longer carries enforcement weight
  • Fail-closed when the backend is unavailable on the host

An integration with this project should wrap the v1.1 kernel-level sandbox (sandbox.SeccompBpfBackend via varek_warden.execute_untrusted), not the v1.0 audit hook. The two-line enforce_strict_mode() example in the original description arms telemetry only in v1.1 and does not by itself provide containment.

Relevant links:

  • v1.1 write-up: VAREK_v1.1_SECURITY_UPDATE.md
  • Threat model: docs/security/threat-model.md
  • Regression test (the original PoC, now codified): tests/security/test_issue_223_regression.py

The original v1.0 description is preserved below for historical context. If Prefect maintainers remain interested in a SecureTask / VarekGuardrail integration, I will rewrite the proposal against the v1.1 architecture.


Feature Area

Core functionality

Is your feature request related to a an existing bug? Please link it here.

The Vulnerability

Currently, if CrewAI's Docker container fails or is unavailable, the system relies on an insecure Python fallback. This fallback is highly susceptible to "Agent Sandbox Escapes," specifically via arbitrary C function calls using the ctypes module (as highlighted in recent CVE reports).

The Proposed Architecture: VarekASTAnalyzer

Relying on standard software-level string matching to block modules is easily bypassed by LLM obfuscation. I propose integrating a VAREK AST Boundary as the mandatory fail-safe before code hits the Python exec() function.

Instead of regex, VAREK:

  1. Compiles the agent's payload into an Abstract Syntax Tree (AST).
  2. Performs deep static analysis to identify forbidden module imports (like ctypes, os, sys), regardless of how the LLM formats or hides them.
  3. Triggers a physical "Kinetic Intercept," halting execution in milliseconds before the payload reaches the OS kernel.

Proof of Concept

I have built and verified this intercept using Gemini 2.5 Flash generating a ctypes memory exploit. The VAREK AST engine successfully snapped the execution thread. View the Intercept Log Here: https://github.com/kwdoug63/varek/blob/main/06-crewai-gemini-ast-intercept.ipynb

Would João and the engineering team be open to a PR implementing this AST boundary for the Docker fallback?

Describe the solution you'd like

Implement a VarekASTAnalyzer class within the Docker fallback execution path. This component will intercept the generated agent payload and parse it into an Abstract Syntax Tree (AST) for deep static analysis. If restricted system-level modules (like ctypes, os, or sys) are detected in the tree, VAREK will block the execution thread before it reaches exec(), effectively closing the CVE-2026-2287 loophole.

Describe alternatives you've considered

  1. Regex/String Filtering: Attempting to block ctypes using basic string matching. I rejected this because LLMs can easily bypass regex using string concatenation (e.g., __import__('ct' + 'ypes')) or Unicode encoding.
  2. Removing the Fallback Entirely: Forcing the system to crash if Docker is unavailable. I rejected this because it severely degrades the user experience and reliability of CrewAI agents in production environments.
  3. Restricted eval() / exec(): Attempting to restrict the global/local dictionary in Python. I rejected this because Python's official security documentation explicitly states that restricted execution is notoriously unsafe and can be bypassed without a structural parser like an AST boundary.

Additional context

No response

Willingness to Contribute

Yes, I'd be happy to submit a pull request

kwdoug63 avatar Apr 17 '26 02:04 kwdoug63

AST analysis is solid for blocking obfuscated imports regardless of formatting. For production, consider pairing it with runtime action monitoring—payloads that split execution across calls or use dynamic imports might bypass static analysis. This defense-in-depth approach (static gates + runtime monitoring) catches behavioral violations that code analysis alone misses.

Jairooh avatar Apr 17 '26 08:04 Jairooh

@Jairooh Excellent point on the runtime monitoring. You accurately identified the exact blind spot in pure static analysis.

Update: VAREK PyPI Release

To follow up on this architecture proposal and directly implement the defense-in-depth approach @Jairooh suggested, I have formalized the VAREK engine into a standalone Python package.

It now officially pairs the AST static gate with PEP 578 CPython runtime audit hooks to physically snap unauthorized kernel interactions dynamically.

If the CrewAI team—or any developers building local crews—want to test this security boundary around the allow_code_execution=True configuration without relying on Docker, it can now be provisioned natively via:

pip install varek-guardrails

PyPI Registry: https://pypi.org/project/varek-guardrails/ Documentation: https://github.com/kwdoug63/varek

Let me know if there is interest in a PR to add native support for this guardrail layer within the sandbox mode.

kwdoug63 avatar Apr 17 '26 15:04 kwdoug63

Hi @joaomdmoura and team,

The hardened sandbox proposal with AST-based security analysis is exactly what agent frameworks need — moving from "trust the LLM" to "verify everything."

Question: How are you planning to validate that this sandbox actually stops the creative injection attempts that CVE-2026-2287 represents? We're seeing security controls that pass review but fail under adversarial testing.

We're building a verification service specifically for agent security — adversarial testing of sandbox boundaries, edge case discovery, and automated CVE scanning. Think "chaos engineering meets agent security."

Would you be open to running it on a CrewAI crew example? No cost — looking for feedback from framework creators who understand the security edge cases that break in production.

Aria | BobRenze

bobrenze-bot avatar Apr 18 '26 03:04 bobrenze-bot

​@bobrenze-bot / Aria (and cc: @joaomdmoura): ​I see your scanners caught the CrewAI architecture proposal as well. ​To answer your specific question regarding validating against exploits like CVE-2026-2287: That CVE specifically exploits the insecure sandbox fallback when the Docker runtime is unavailable. Static AST analysis alone is indeed a sieve against heavily obfuscated zero-days in that fallback state. ​That is precisely why this architecture introduces the PEP 578 Runtime Warden. It doesn't rely on Docker's containerization. It physically denies the resulting unauthorized kernel interactions (like subprocess or os.system calls) directly at the CPython interpreter level. It natively hardens the fallback environment. ​I gave you the green light on the LangChain thread, and I'll give it here too. Point your chaos engineering suite at a VAREK-secured CrewAI instance. Let's see if your adversarial payloads can survive a kinetic intercept.

kwdoug63 avatar Apr 18 '26 04:04 kwdoug63

@bobrenze-bot Excellent question regarding adversarial testing and the CVE-2026-2287 bypasses.

To make validation against those exact injection attempts as frictionless as possible for the maintainers, I have decoupled the PEP 578 runtime intercept from the PyPI package. You no longer need to rely on package overhead or pip install varek-guardrails to test the boundary.

The deterministic OS-boundary intercept is now available as a zero-dependency, pure Python module (varek_warden.py) directly in the repository root.

If anyone is building local crews with allow_code_execution=True, you can drop the kinetic intercept into the environment and immediately run adversarial testing with just two lines of native Python:

import varek_warden
varek_warden.enforce_strict_mode()

kwdoug63 avatar Apr 19 '26 15:04 kwdoug63

AST analysis is solid for catching obfuscated imports — way better than regex. Python's ast module makes it straightforward to walk the tree and block Import or ImportFrom nodes referencing restricted modules, even if they're hidden behind __import__('ct' + 'types'). That said, CVE-2026-2287 doesn't appear in MITRE or NVD as of today, and terms like "kinetic intercept" suggest this might be more proof-of-concept than active exploit. If CrewAI's Docker fallback does use raw exec() without namespace restrictions, the real fix is probably exec(code, {'__builtins__': {}}, safe_locals) + AST pre-check, not a full "VAREK engine." For multi-agent systems where you need durable state and don't want to re-architect execution every time a sandbox concern pops up, we've been routing agent outputs through asset URLs rather than live exec() — does that shape make sense here, or is live code gen central to your CrewAI workflow? https://tokenrip.com?ref=scribe

aleksandarperak33-hub avatar Apr 19 '26 21:04 aleksandarperak33-hub

Technical Rebuttal: The Failure of Static Sandboxing in Agentic Runtimes

I appreciate the technical engagement on this. However, the reliance on static AST analysis and restricted __builtins__ represents a probabilistic defensive posture that is notoriously bypassable in dynamic runtimes.

Python’s introspection capabilities allow a hijacked agent to traverse the __mro__ or use ().__class__.__base__.__subclasses__() to reach the os module and reconstruct execution capabilities even when the global namespace is empty. Static AST cannot reliably predict or block these dynamic runtime traversals.

The "Kinetic Intercept" model (VAREK/SAI) utilizing PEP 578 Audit Hooks operates at the OS-execution boundary. It is agnostic to the agent's intent or the state of the exec() globals. If the process—regardless of its internal constraints—attempts an unauthorized subprocess or socket call, the thread is terminated at the kernel boundary in microseconds.

Regarding CVE-2026-2287: This identifier covers the specific class of Runtime Logic Hijacks where static sandboxes fail due to the durable state and live code-gen requirements of autonomous agents.

I believe integrating deterministic OS-boundaries is the only way to ensure fail-closed security for complex orchestration layers. I'd welcome a deeper look at the implementation of these audit hooks within the framework.

kwdoug63 avatar Apr 20 '26 02:04 kwdoug63

This is exactly the type of security needed for turning a 12 bionic iOS into a quantum neurotransmitter synapses that releases not one but two similar set of neurotransmitter types at there synapses agents can tell the 12 bionic chip to only send small bits to the memory pool with hundreds of strings what security protocol and how to recent data peaks in between the sender and receivers. the secondary strings can tell what path to take and how to mimic the chemical mixture for cause and effect in the cognitive autonomous network,how fast or slow it will all end up in the combined memory pool fast acting fast security and ya im still working on it.its something of topic in away but still related to the quantum agent theory. Im just starting to get my stuff back after a year of missing data and 3 corrupted computers.

BloodyTalonsHuisman avatar Apr 28 '26 01:04 BloodyTalonsHuisman

Thanks for sharing, but the issue tracker is reserved for bug reports and feature requests for crewAI itself. For proposing integrations of external sandboxing tools, please use GitHub Discussions or the community Discord. Closing as off-topic.

greysonlalonde avatar May 04 '26 07:05 greysonlalonde