Automating Kubernetes security fixes with AI agents and GitOps
A new architectural pattern uses AI agents to convert Falco runtime alerts into verified Kyverno policies delivered as GitLab merge requests.
Security teams often face a bottleneck between detecting a threat in a running Kubernetes container and applying a permanent fix. A new approach presented by the Cloud Native Computing Foundation (CNCF) bridges this gap by using an AI agent to translate runtime alerts into code changes. This system integrates Falco for detection, Kyverno for policy enforcement, and GitOps workflows to ensure every mitigation is reviewed and versioned.
What happened
The CNCF published a detailed architectural pattern that demonstrates how an AI agent can act as an intermediary between runtime security tools and configuration management. In traditional setups, security scanning occurs before deployment, leaving running containers vulnerable to zero-day exploits or misconfigurations that pass initial checks. When a tool like Falco detects suspicious behavior, the alert typically sits in a queue for manual analysis. By the time an engineer investigates and patches the issue, the same insecure configuration may have been deployed elsewhere.
This new model automates the triage and fix preparation phases. Instead of creating a ticket, the system generates a merge request in a Git repository. The AI agent analyzes the alert, drafts a Kyverno policy to block the specific attack vector, and hardens the workload manifest. Crucially, the agent does not apply changes directly to the cluster. It submits its work for human review, ensuring that deterministic code verifies the safety of the proposal before any engineer approves it.
The architecture relies on established CNCF graduated projects to maintain trust and stability. Falco handles runtime detection by monitoring system calls and audit logs. Kyverno serves as the policy engine, validating the AI’s proposals against the live cluster state. The entire process is orchestrated through a Python service using LangGraph and an Azure OpenAI model, with GitLab managing the version control and CI/CD pipelines. This setup ensures that the AI layer sits on top of components that operators already use and trust in production environments.
How it works
The system operates on a closed feedback loop where the AI proposes, deterministic code verifies, and humans decide. When Falco detects an event, such as a binary execution inside a container, it sends a webhook to the AI agent. Before the large language model processes the alert, deterministic filters remove noise and known benign activities. This step reduces cost and prevents the model from being distracted by routine platform operations.
The AI agent then enriches the alert with context from the Kubernetes API, including pod ownership and image details. It assesses the risk and confidence levels separately. If the risk is high and confidence is sufficient, the agent drafts a mitigation. This includes a Kyverno policy set to deny mode and a hardened version of the workload manifest, adhering to standards like the Kubernetes Pod Security Standards. The Kyverno CLI then tests this proposal against the live cluster to ensure it blocks the vulnerable configuration without affecting other workloads.
Once verified, the agent opens a merge request in GitLab. The request contains the policy, the manifest changes, and a detailed explanation of the incident and reasoning. Engineers review the change just like any other code contribution. They can comment on the request, prompting the agent to revise and re-verify the fix. After approval, the CI/CD pipeline deploys the new policy, preventing the vulnerability from recurring in future deployments.
Key details
- Detection speed: In live tests, the system detected and assessed risks within the same second as the attack, assigning risk scores of 0.98 and 0.99.
- Fix generation time: The agent produced a verified merge request with a Kyverno policy and hardened manifest in 1 minute and 45 seconds.
- Safety verification: The Kyverno CLI ensures that proposed policies do not block unrelated workloads, maintaining a blast radius of zero in tests.
- Human-in-the-loop: The AI agent has read-only access to the cluster and cannot apply changes directly, requiring engineer approval via merge requests.
- Revision capability: Engineers can request changes in merge request comments, with the agent able to revise and re-verify fixes in approximately 50 seconds.
- Compliance support: All automated and human decisions are recorded in Git and the application database, aiding compliance with regulations like NIS2 and DORA.
Why it matters
For software engineers and DevSecOps teams, this approach addresses the critical gap between runtime detection and permanent remediation. Traditional reactive methods often result in one-off fixes to running pods, which do not prevent the same misconfiguration from being redeployed. By converting alerts into infrastructure-as-code changes, this method ensures that security fixes are persistent and version-controlled. It reduces alert fatigue by filtering noise and providing context-rich assessments, allowing engineers to focus on high-value review tasks rather than repetitive investigation.
Furthermore, the integration with GitOps workflows aligns security practices with modern development standards. Since the repository remains the single source of truth, there is no drift between the desired state and the actual cluster configuration. This method also enhances explainability and accountability. Every decision made by the AI is documented in the merge request, providing a clear audit trail. While full autonomy remains risky due to potential LLM misinterpretations, this hybrid model leverages AI for speed and human judgment for safety, offering a practical path toward more resilient Kubernetes environments.
What you can do
- Evaluate your current runtime security workflow to identify bottlenecks between alert detection and fix implementation.
- Implement Falco for runtime threat detection and configure it to forward alerts to a central processing service.
- Adopt Kyverno for policy-as-code management, using its CLI to validate policies against your cluster before deployment.
- Establish a GitOps workflow where all cluster changes, including security policies, are managed through merge requests.
- Experiment with AI agents for alert triage, ensuring they operate with read-only permissions and require human approval for changes.
- Define clear metrics such as mean time to detect and time to verified fix to measure the effectiveness of automated security responses.



