🛡️️ How We Built an Autonomous AI Vulnerability Remediation Engine on Google Cloud with Gemini 3.7 & Governed Agent Gateways
Eliminating 40,000 monthly enterprise security alerts, accelerating MTTR from 1.5 hours to 1.8 seconds, and closing OWASP LLM08 with Google Cloud Armor L7 WAF, In-Process Egress Tool Governance, and Automated Day-2 Maintenance.
The Enterprise Dilemma: 40,000 Alerts, 90 Minutes per Fix, and Alert Fatigue
If you manage application security or cloud infrastructure in an enterprise or financial institution, this scenario will sound painfully familiar:
Every week, your CI/CD pipelines, container registries, and runtime cloud monitors generate tens of thousands of alerts. Between static application security testing (SAST), dynamic web scans (DAST), software composition analysis (SCA), and container runtime Common Vulnerabilities and Exposures (CVEs), a mid-sized enterprise easily generates 40,000 vulnerability alerts every month.
In traditional operations:
An average security engineer or developer spends 90 minutes (1.5 hours) manually triaging an alert, checking whether the vulnerable function is actually reachable, authoring a secure code patch, testing for functional regressions, and opening a pull request.
At a standard fully loaded engineering cost of $120/hour, resolving 40,000 alerts manually costs an astronomical $4,680,000 per month ($56.16 Million per year).
Mean Time to Remediate (MTTR) stretches from 14 to 45 days, leaving critical zero-day exploit windows wide open.
Over the last two years, organizations tried plugging basic Large Language Model (LLM) wrappers into their pipelines to draft automated fixes. But in regulated banking environments, this created a new nightmare:
Excessive Agency (OWASP Top 10 for LLMs — LLM08), unconstrained tool executions, prompt injection smuggling via malicious CVE descriptions, and code hallucinations that broke production builds.
To solve this, we built OneShield: an enterprise-grade, autonomous multi-agent vulnerability lifecycle management and automated remediation engine. Powered by Google Gemini 3.7 Flash, Google Cloud Armor L7 WAF, In-Process Egress Tool Gateways, and Google Cloud Security Command Center (SCC), OneShield slashes MTTR for low-risk alerts from 1.5 hours to 1.8 seconds and cuts operational costs by 99.9997% — operating safely for just $19.46 per month.
Here is how I architected working with FDE to get it deployed, and validated it on Google Cloud Platform (GCP).
The Core Paradigm: The “Shift-Down” Governance Philosophy
When Google Cloud published their blueprint on the Gemini Enterprise Agent Platform (GEAP), one core philosophy stood out: Shift-Down Governance.
Most AI prototypes try to enforce safety via “prompt engineering” (telling the model: ”Please don’t execute unauthorized tools”). In production, this is a fatal flaw. Attackers easily bypass natural-language guardrails via indirect prompt injections and delimiter smuggling.
Shift-Down Governance means moving security constraints down from soft prompt vibes into hard, deterministic infrastructure policy enforcement points (PEPs):
To achieve zero-trust data residency and sub-millisecond execution, OneShield establishes a clear Three-Tier Gateway Topology:
1. Ingress Gateway (Google Cloud Armor L7 WAF): Protects the external HTTP perimeter against DDoS attacks, automated scanner probes, and OWASP Top 10 exploits for ~$10.03/month.
2. Model Inference Gateway (LiteLLM + Presidio DLP): In-cluster proxy delivering zero-trust PII redaction (scrubbing credit cards, SSNs, and IBANs), Redis semantic caching (0ms repeat latency, $0.00 token cost), and dynamic routing to Gemini 3.7 Flash.
3. Egress Tool Gateway (ToolExecutionRouter PEP): In-process Policy Enforcement Point governing all outbound tool executions with agent-to-tool Role-Based Access Control (RBAC) and 4-Eyes Dual-Key Quorum gating.
🏛️ End-to-End System Architecture
Below is the complete architectural flow of OneShield, from raw vulnerability ingestion to Sigstore Cosign keyless admission gating on Google Kubernetes Engine (GKE):

The 11 Operational Lifecycle Stages:
- Ingress & Protection (<1ms): Cloud Armor inspects HTTP envelopes and enforces rate-limits.
- Threat Intelligence & Grounding (<80ms): Vulnerability context grounded against 1,685 active CISA KEV entries, EPSS probabilities, and runtime container SBOMs.
- Multi-Agent Orchestration (1.8s): LangGraph pipeline routes tasks between high-reasoning (gemini-3.7-flash) and budget (gemini-2.5-flash-lite) models.
- DevSecOps Governance Gating (<50ms): Triaged resolution routing (AUTO_PATCH_PR, BLOCK_DEPLOYMENT, ALLOW_SIGN).
- Tool Execution Gateway (<0.2ms): In-process Policy Enforcement Point enforces strict RBAC matrices (OWASP LLM08).
- End-to-End Observability: W3C distributed trace context propagation via OpenTelemetry Python SDK.
- Security Audit Logging: Immutable Cloud Logging stream recording every model decision and tool parameter.
- Distributed Tracing: Cloud Trace span waterfalls tracking latency across WAF, FastAPI, LiteLLM, and Vertex AI.
- Metrics & Dashboards: Real-time Cloud Monitoring metrics tracking Compilation Pass Rate and token costs.
- Policy Enforcement: Kyverno admission webhooks verify Cosign keyless signatures at GKE container admission.
- Data & Verdicts Store: Cloud SQL PostgreSQL 16 persistence for historical scan verdicts and audit diffs.
💡 The Hard-Won Engineering Discovery: WAF Rule Ordering
Building agentic systems in enterprise environments exposes failure modes you will never encounter in a local notebook:
1. The Cloud Armor WAF Rule Ordering & JSON False-Positive Traps
During initial staging penetration tests, two unexpected WAF phenomena hit us:
- Rule Ordering: Rate-limiting rules with “allow” actions can short-circuit security inspection rules. We prioritize OWASP CRS inspection rules (Priority 2000–2300) over anti-DDoS rate-limiting (Priority 5000).
- JSON False Positives: We enabled standard JSON parsing and used Google Cloud CEL to ensure body anomaly rules don’t mistake scanner JSON syntax for SQL injection.
2. In-Process PEP vs. Network Proxies
Autonomous agents frequently invoke tools in iterative loops. If each tool call traverses an external network gateway, a 4-step remediation loop incurs 400ms–600ms of pure network proxy latency overhead.
- Our Solution: An in-process ToolExecutionRouter (app/core/tool_gateway.py). Operating directly inside the application runtime, it evaluates RBAC whitelists in < 0.2 ms with zero network penalty.
- 4-Eyes Dual-Key Quorum: While low-risk vulnerabilities are fully auto-remediated in our benchmark 1.8 seconds, high-impact destructive tools (e.g., merging code or modifying Cloud SCC findings) are intentionally slowed down. They require independent cryptographic approvals from both a lead_developer and a security_officer with a 4-hour TTL (expires_at), completely shutting down autonomous privilege escalation.
🧪 Continuous Quality: The 4-Gate Evaluation Flywheel
To satisfy enterprise model risk governance (NIST AI RMF 1.0 & OWASP LLM02), candidate patches synthesized by Gemini 3.7 Flash must pass four deterministic quality gates before code is ever proposed:
Candidate Patch ──> [Gate 1: AST Parse] ──> [Gate 2: Anti-Tamper] ──> [Gate 3: Ephemeral Sandbox] ──> [Gate 4: Exploit Fix] ──> Production PR
- Gate 1 (AST Syntax Parsing, <20ms): Generates Python/Java Abstract Syntax Trees to guarantee zero syntax or compilation errors.
- Gate 2 (Anti-Tamper Scanner): Rejects deceptive model edits that attempt to “fix” an alert by simply deleting security annotations (e.g., stripping Spring Security @PreAuthorize).
- Gate 3 (Ephemeral Sandbox Gate): Powered by EphemeralSandboxRunner (app/guardrails/patch_validator.py), executes candidate patches in an isolated, air-gapped subprocess (network_mode: none, 5.0-second hard timeout) against existing unit tests to prevent regressions.
- Gate 4 (Negative Exploit Verification): Confirms that the original exploit vector is safely neutralized by the patched code.
📊 Reliability Metrics Triad (Production Benchmarks)

💰 The Financial Math: $4.68 Million vs. $19.46 per Month
Here is the hard financial reality for an enterprise managing 40,000 monthly vulnerability alerts:

Per-Alert Gemini Token Breakdown:
- SAST (Java/SQLi): 167 prompt / 697 completion (gemini-3.7-flash) →→ $0.000222 / alert
- DAST (React/XSS): 320 prompt / 350 completion (gemini-3.7-flash) →→ $0.000129 / alert
- SCA (Container CVE): 210 prompt / 150 completion (gemini-2.5-flash-lite) →→ $0.000060 / alert
By pairing high-throughput container SCA scans with Gemini 2.5 Flash Lite and deep reachability analysis with Gemini 3.7 Flash, the engine keeps total AI token spend under $10.00 per month.
🛠️ Day-2 Operations: Living Infrastructure Hygiene
Deploying an autonomous agent platform is only Day 1. To ensure long-term stability:
- Automated Maintenance CI/CD (scheduled_maintenance.yml): Weekly cron (0 4 * * 1) executing pip-audit, Trivy container CVE scans, and automated PR generation.
- Monthly Helm Upgrades (helm_maintenance.sh): Zero-downtime rolling upgrades for LiteLLM, Redis, and Kyverno with automated 120s rollback circuit breakers.
- Multi-Pod Distributed Concurrency: Redis distributed locking (DistributedWorkflowStore.lock with 30s TTL) to serialize agent graph state transitions across GKE replicas, with automatic fallback to local asyncio.Lock.
- Comprehensive Test Suite: Verified by 69 automated unit and integration tests passing with 0 warnings.
4 Rules for Building Enterprise AI Agents in 2026
- Shift Down from Prompts to Policy Enforcement Points: Never trust an LLM to self-govern its tools. Implement deterministic RBAC matrices and Pydantic validation contracts at the code or gateway layer.
- Beware WAF Rule Ordering: In Google Cloud Armor, placing rate_based_ban above OWASP CRS rules bypasses threat inspection for conforming traffic. Always order inspection rules first.
- In-Process PEPs Beat Network Gateways for Tool Loops: If your agents call multiple tools per turn, route tool calls in-process (<0.2ms) rather than adding 50–150ms external network gateway hops.
- Deterministic AST Validation is Non-Negotiable: Never push AI-generated code directly to production. Always gate proposed patches through AST parsing, anti-tamper scanners, and ephemeral test sandboxes.
🌟 Conclusion
Autonomous AI agents represent the biggest leap forward in DevSecOps since the inception of continuous integration. But enterprise adoption requires governance, determinism, and cost efficiency.
By pairing Google Gemini 3.7 Flash with Google Cloud Armor L7 WAF, In-Process Tool Gateways, and Continuous Evaluation Flywheels, OneShield proves that organizations can autonomously remediate 40,000 monthly vulnerabilities, accelerate MTTR by 3,000x, and save $4.67 Million every month — safely, reliably, and deterministically.
🔗 Resources & Open-Source Code
- Check out the full implementation in our GitHub Repository, and if you’re building agentic workflows on GCP, let me know what challenges you’re facing in the comments!
- Google Cloud Gemini Enterprise Agent Platform: cloud.google.com/vertex-ai
- Google Cloud Armor: cloud.google.com/armor
🛡️️ How We Built an Autonomous AI Vulnerability Remediation Engine on Google Cloud with Gemini 3.7 was originally published in Google Cloud – Community on Medium, where people are continuing the conversation by highlighting and responding to this story.
Source Credit: https://medium.com/google-cloud/%EF%B8%8F%EF%B8%8F-how-we-built-an-autonomous-ai-vulnerability-remediation-engine-on-google-cloud-with-gemini-3-7-802d88430acb?source=rss—-e52cf94d98af—4
