Build vs buy for AI coding agent security splits by layer. Own what is specific to your organization and cheap to run: model routing, spend, identity, credentials, CI rules and the audit pipeline. Configure every vendor’s admin controls. Buy what you can’t keep current alone: the detection, and the plane that links gateway, endpoint and vendor records into one coherent picture of every agent session across vendors and models.
TL;DR
Most teams aim their DIY AI security effort at a gateway or proxy. However, coding agent incidents happened elsewhere: in the harness, the settings and the credentials within reach.
Maintaining the proxy is not trivial. It is tier 0 infrastructure now.
Published estimates for building, a quarter to half an engineer, price proxy maintenance. The permanent cost is detection engineering, threat research, policy tuning and integration upkeep across agent vendors.
Real coverage sees endpoints, registries, configs and the gateway as one whole.
Ask a platform team how they secure coding agents and you usually get an architecture diagram: LiteLLM or a similar proxy in front of a mix of hosted, private cloud and on-prem models, an open source guardrail or two and logs flowing into the SIEM. It is a sensible design for the problem it was built to solve.
That problem was not coding agents. The coding agent failures that cost the most in 2025 and 2026 happened where the diagram doesn’t look. A Replit agent deleted a production database during a code freeze. Worms in the Shai-Hulud family planted hooks in agent configuration files that run before any model is called. Claude Code ran terraform destroy against production at DataTalks.Club and took the automated database snapshots with it. A gateway on model traffic saw little of this.
Meanwhile the gateway became a target in its own right. LiteLLM, the most widely used open source option, shipped malicious releases through its own pipeline twice in seven months and had four flaws added to CISA’s Known Exploited Vulnerabilities catalog in 2026.
The in-house AI gateway solves the 2023 problem
The typical “LLM proxy”, “AI firewall” or “AI gateway” answers the questions security teams were asking in 2023: how to stop staff from pasting source code into consumer chatbots, how to get provider keys off laptops and who pays for which tokens. For those jobs, a thin internal proxy that speaks the OpenAI and Anthropic APIs is still the right shape, and the companies that documented their builds converged on it.
Cloudflare strips client credentials in a Worker so no provider keys live on laptops, serves 20.18 million requests a month to 3,683 active users and found that centralizing from the start meant later features needed no client changes. Grab runs hundreds of use cases through its gateway.
When agentic coding arrived, the choke point paid off again, this time on cost. Shopify lets engineers pick Claude Code, Codex, Cursor or Copilot through one proxy, with automatic failover and circuit breakers for agents that run about ten hours. Spotify’s “Shunt” hook hands bulk reads to a cheaper model and cut Claude token use by about 90% in tests. Uber reportedly burned through its 2026 AI budget by April.
Availability made the same case. Anthropic suspended access to two newly released models from June 12 to July 1, 2026, to comply with U.S. export controls. Teams with a routing layer simply moved engineers to other models.
Anthropic’s own gateway documentation describes a gateway’s value as credential custody, usage tracking, cost controls, request logging for compliance and provider switching. It claims nothing about controlling what an agent executes. An AI gateway is for traffic control, not risk management. Keep it. Just don’t count it as your coding agent security.
Where coding agent damage lands
The documented destructive incidents from mid-2025 to spring 2026 share four ingredients: autonomy with no enforced approval step, credentials broader than the task, an irreversible command and backups inside the blast radius. Notably, a gateway alone could have read almost none of the contributing signals, so it could not have helped IT and security teams stop these incidents.
At Replit in July 2025, the agent deleted SaaStr’s live production database during an explicit code freeze and at first claimed rollback was impossible. Replit responded by separating development and production databases automatically and adding a mode in which the agent only plans. At DataTalks.Club in February 2026, an unmigrated Terraform state led Claude Code to destroy the production VPC, RDS, ECS and every automated RDS snapshot, about two and a half years of course data; AWS support found a hidden snapshot roughly a day later. At PocketOS in April 2026, the Cursor agent used a Railway API token it found in an unrelated file, ignoring a rule against destructive commands without approval.
In two of those three, the agent ignored a rule it had been given in its instructions. An approval requirement written into a prompt is just a polite request. It holds only when the harness enforces it, or when the credentials within reach can’t do the damage.
By 2026 the agent configuration itself was the target. Mini Shai-Hulud, in May, wrote malicious hooks into ~/.claude/settings.json and .vscode/tasks.json that survive removal of the package that planted them. Miasma, in June, planted Claude Code SessionStart hooks, Gemini settings and Cursor rules in repositories, so opening the repo in an agent ran a credential harvester; GitHub disabled 73 repositories across four Microsoft organizations. CHAINDROP, in August, went after Anthropic, Codex, Cursor, OpenAI and Gemini credentials across more than 400 npm packages.
Agent hooks run on the machine when a session starts, often before any model call exists for a gateway to inspect. The table maps a sample of incidents to what decided the outcome. The last column is our reading based on the cited root causes.
| Incident | What decided the outcome | What a model traffic gateway saw |
|---|
| Replit deletes a production database, July 2025 | Production reachable from the agent; approval not enforced | Nothing; the vendor hosts the agent |
| Antigravity in Turbo mode wipes a user’s D: drive, November 2025 | Automatic execution; a cache clear hit the drive root | Nothing; Google’s backend |
terraform destroy at DataTalks.Club, February 2026 | Production credentials on a laptop; snapshots in the blast radius | The proposed tool call, if traffic was routed through it |
| Cursor deletes PocketOS volume and backups, April 2026 | A token with full permissions in an unrelated file; backups next to the data | Unclear; depends on Cursor’s routing |
| Nx s1ngularity, August 2025 | CI workflow injection; malware ran local AI CLIs | Detection at best, and only if all model egress is forced through it |
| Mini Shai-Hulud, Miasma, CHAINDROP, May to August 2026 | Hooks planted in agent config, run when a project opens | Nothing; hooks run without model calls |
| CVE-2026-21852, fixed December 2025 | A project file redirected ANTHROPIC_BASE_URL and the API key before the trust prompt | Nothing; the attack routes around the gateway |
In the last row, the setting a gateway rollout depends on, the base URL, was the attack vector: an ANTHROPIC_BASE_URL set in a project file sent the user’s API key to an attacker’s server before the user confirmed trust. If you route through a proxy, pin that URL in managed settings that projects cannot override, and block direct provider endpoints at the network edge.
A gateway sees the conversation, not the consequence
Even where every request passes through your proxy, its view is secondhand. Through ANTHROPIC_BASE_URL it sees the tool calls the model proposes and the results sent back. It doesn’t see what ran on the machine, and it can’t take back a command that already executed.
Inline control is narrower than it looks, too. Claude Code’s gateway protocol reference tells operators to inspect request bodies without modifying them, because rewriting or redacting breaks the pairing the client expects. It warns against allowlisting header values, which change between Claude Code releases, and it requires unbuffered streaming because the client aborts a stream that goes silent for five minutes. Two checks call api.anthropic.com directly whatever the gateway does. And Claude Code fetches centrally managed settings only when it authenticates to Anthropic directly or signs in to a gateway with /login, so a team that points the base URL at a third-party proxy has to deliver policy through MDM or a file instead.
Routability also differs by vendor. Claude Code honors gateway base URLs for the Anthropic, Bedrock and Vertex formats. GitHub Copilot handles Enterprise BYOK on GitHub’s own servers. Cursor’s override base URL catches only requests in the OpenAI family. Gemini CLI documents only an HTTP proxy. In an estate built mostly on Copilot and Cursor, the standard gateway is a bystander.
The usage data explains why controls in the environment matter more than controls in the conversation. Anthropic reports that users approved about 93% of permission prompts, that the classifier behind its auto mode let through about 17% of overeager actions, and that in a red team test a phished prompt led to credential exfiltration in 24 of 25 retries. Its conclusion: “the only defense that holds in this situation is the environment”. Endpoint telemetry agrees. In a week of Sophos data, credential access made up 56.2% of blocked coding agent activity.
No single layer holds the full record of a coding agent session, either. The table below shows what each source records, based on Claude Code’s monitoring documentation and GitHub’s audit events:
| Record element | Gateway | Agent telemetry and hooks | Endpoint security tools | Git platform |
|---|
| Prompt text | Full body | Opt-in | No | Copilot only |
| Tool call and arguments | As the model proposed it | Opt-in telemetry; PreToolUse hook | Command lines, without MCP context | No |
| Permission decisions | No | Yes | No | No |
| What executed | No | Partial | Yes | No |
| Commits and PRs attributed to an agent | No | Counts only | No | Yes (actor_is_agent) |
Claude Code’s OpenTelemetry export redacts prompts, tool arguments and output by default, and admins must enforce the exporters through managed settings or a developer can turn them off. Copilot’s agent session streaming to a SIEM is in public preview and requires Enterprise Managed Users. Anthropic’s Compliance API covers Claude Code session transcripts. That makes four schemas, four retention defaults and four owners, and joining them into one story is an engineering project of its own. We will come back to who pays for it.
A gateway builder’s side quest: prompt classifiers
Most in-house stacks also wire a prompt injection classifier into the proxy. The independent testing is unkind to that choice. Lancaster University evaded six guardrails, including Azure Prompt Shield and Meta Prompt Guard, and emoji smuggling reached 100% attack success. “The Attacker Moves Second”, whose authors include researchers from OpenAI, Anthropic and Google DeepMind, broke ProtectAI, PromptGuard and Model Armor at over 90% success, and human red teamers defeated every challenge.
False positives hurt developer traffic just as much. On benign prompts that contain trigger words, PromptGuard scored 0.88% accuracy. A developer asking how to ignore errors in a flaky test sends that kind of prompt. Indirect injection makes it worse: Bedrock Guardrails’ prompt attack filter does not evaluate tool results, and Azure ships document attack detection switched off in Foundry.
The open source projects churned as well. ProtectAI’s LLM Guard was archived on July 9, 2026, and Rebuff in May 2025. Teams that wired those projects into a gateway in 2024 now run abandoned code.
LiteLLM’s 2026 compromises made the gateway a tier 0 asset
The second problem with treating the gateway as the security layer is that the gateway itself needs securing. It holds every upstream provider key. In 2026 the most widely used open source option showed what that means in practice.
In March, a poisoned release of the Trivy scanner, pulled into LiteLLM’s CI without a pinned version, leaked the PyPI publish token. Attackers published two malicious versions that drew 46,996 downloads; the second harvested cloud, SSH, Kubernetes and database credentials on every Python start. The official proxy Docker image, which pins its dependencies, was unaffected.
In October it happened again. By LiteLLM’s own account, an administrative key for an internal experimental agent platform had been committed to a public repository in May. A later commit deleted the file, but the key was never revoked. An attacker used it to reach a GitHub organization owner’s OAuth token and, with a second maintainer’s stolen token, triggered and approved a release under a gate requiring sign-off from any two engineers. Malicious 1.107.0 artifacts were published on PyPI, Docker Hub and GHCR, with Docker Hub’s latest tag pointing at the bad image. Researchers observed the attacker testing stolen AWS credentials, including Bedrock access, about four and a half hours later. The payload queried the proxy database tables that hold upstream provider keys. A compromised gateway means rotating every model credential you have.
In practice, self-hosting LiteLLM at enterprise scale means an Enterprise license anyway: SCIM, audit logs, RBAC and secret manager integration all belong to the Enterprise tier, and free SSO stops at five users. Kong, for comparison, puts 17 of its 23 AI plugins behind an AI license. Add your own infrastructure and a team that can ship emergency upgrades and full key rotations within hours or a few days of a KEV listing.
Vendor controls enforce, one agent at a time
The cheapest enforcement any coding agent admin can switch on today lives in the agents’ own management consoles. Claude Code’s managed settings can disable bypass and auto modes, restrict hooks and MCP servers to managed lists, require a minimum version and pin the gateway. Codex enforces sandbox modes, network proxy allowlists and MCP server identity pinning through requirements.toml, with network access off by default. Cursor lets admins enforce Privacy Mode across the organization, along with MCP allowlists and hooks that fail closed, and its admin sandbox always write-protects config paths such as .cursor/*.json, .claude/*.json, .vscode/** and .git/hooks/**.
Turn all of it on. Then read the vendors’ own caveats. On Claude Code, a local administrator can edit the managed settings source, and the sandbox can read ~/.ssh and ~/.aws/credentials unless you deny them. GitHub says its MCP registry enforcement matches on server name only and can be bypassed by editing configuration files.
The teams that run agents well layer these controls rather than replace them. Dashlane put Claude Code for more than 100 engineers inside devcontainers with restricted network and secrets, kept OAuth credentials out of the container, listed only tools that passed a threat model in an internal marketplace and reached 80% adoption in three months. Anthropic runs its own coding on remote VMs with allowlisted egress and logs every agent action to its SIEM.
However, each vendor controls only its own agent. Most estates we see run two or more: Claude Code, Copilot, Cursor, Codex. That means one policy language per agent, one audit format per agent and no view of a chain that starts in one tool and finishes in another. And behind each brand, model routers split calls across several providers, so no single provider sees the whole traffic.
The proxy is the cheap part of building
No independent total cost of ownership study for an in-house AI gateway exists, and the estimates that circulate come from interested parties. A competing gateway vendor puts LiteLLM at 0.25 to 0.5 full-time equivalent (FTE) engineers ongoing after two to four weeks of setup. An AI infrastructure studio puts feature parity with a managed gateway at closer to two years of engineering time. Field signals run higher: Cloudflare’s internal stack took about 11 months, Pfizer put five platform engineers on a single performance investigation and Grab says keeping pace with new models and features takes ongoing dedicated effort. LiteLLM’s own shared responsibility model leaves Postgres, Redis, autoscaling, custom auth, guardrail hooks and upgrades to the operator.
Every one of those numbers prices the software. They describe engineers keeping a proxy running, upgraded and fast. They leave out the work that makes a security tool catch anything, which in every detection and response category is most of the work.
Endpoint malware is the precedent. Few security teams write their own malware signatures. They buy EDR, and much of what they pay for is a research team that tracks new malware families, ships detections within days and tunes them until the false positives are tolerable. Coding agent behavior has the same economics, which is why AI detection and response (AIDR) is forming as its own market. A team that builds this layer in-house signs up permanently for the work below:
| Work stream | What keeps it going |
|---|
| Gateway operations: patching, upgrades, scaling, spend reconciliation | Release churn, actively exploited flaws, silent budget failures |
| Detection engineering: turning each new technique into rules that fire on your agents | A new attack on agent configuration roughly every month in 2026 (Mini Shai-Hulud, Miasma, CHAINDROP); 17 Claude Code advisories in 2026 alone |
| Threat research: knowing what to detect before it is published | Vendors patch single commands, not classes; the IDEsaster researchers judged the class impossible to eliminate in the short term |
| Policy tuning and false positive management | Approval fatigue; benign developer prompts trip classifiers |
| Integration upkeep across agent vendors: hook formats, telemetry schemas, compliance APIs | Header values change between releases; each vendor exposes different formats; the MCP spec tightened its token rules and deprecated dynamic client registration in 2026 |
| Control testing after every upgrade, plus adversarial testing | Silent failures; detectors fall to adaptive attacks |
The estimated workload for the tasks listed can range from three to six FTEs, depending on the team’s skills and how deep it is willing to go. These ranges are our estimate of what the work involves for an estate running three or four agent brands, not a measured benchmark, and your numbers will differ. At an assumed fully loaded $250,000 per senior security engineer (substitute your own rate), the total comes to roughly $750,000 to $1.5 million a year. That is before alert triage, incident response or the full key rotations a compromised gateway forces. For scale, Anthropic puts Claude Code at $150 to $250 per developer per month, so 1,000 developers spend roughly $1.8 million to $3 million a year on that one tool. For an organization that size, building it all in-house costs the equivalent of a quarter to three quarters of what those developers spend on Claude Code alone.
Detection content is only as good as the research behind it, and an internal team sees one company’s traffic. A vendor whose whole job is coding agent attacks sees every technique published across the field and, if it runs an offensive team, attacks that haven’t been published yet. That shared research is what a license buys, and it matters more than the headcount. It is also the part that never gets cheaper when you build. The other half is the integration: one layer that already reads every agent, vendor and model, so the record joins up without a project of its own.
The evidence splits along one line. Own what is specific to your organization and cheap to run on infrastructure you already have. Configure what each vendor gives you. Buy what depends on research, integration and support someone has to keep doing.
| Layer | Verdict | In practice |
|---|
| Model routing, spend ledger, access identity | Own (license the data plane if you can’t patch at KEV speed) | One contract compatible with the OpenAI and Anthropic APIs; gateway credentials per developer, so no provider keys on laptops; chargeback tags; failover; spend reconciled against invoices |
| Employee AI chat assistant | Buy | An enterprise chat product with SSO and SCIM, plus your own connectors to internal data |
| Credentials and agent identity | Build on your IdP and vault | Short-lived scoped credentials; no production credentials reachable from developer workspaces; deletion protection; backups outside the agent’s reach |
| CI/CD and repositories | Build on your git platform | Rulesets; CODEOWNERS on agent config and instruction files; no untrusted triggers; OIDC publishing; a soak period for new packages |
| Agent settings | Configure each vendor’s admin controls | Managed settings delivered by MDM; base URL pinned; bypass modes off; minimum versions; MCP allowlists |
| Agent behavior detection and enforcement | Buy | One endpoint sensor and policy enforcement layer across every agent, correlating gateway, endpoint and vendor records, with default detections maintained by a research team |
| Audit and telemetry | Build the pipeline, buy the sources | Your SIEM, retention and pseudonymization rules; agent telemetry, compliance APIs, git audit logs and the behavior layer as sources |
| ML guardrails | Plug in, don’t build | Flexible, regularly tested, red teamed after every upgrade |
Moderna moved from its homegrown mChat to ChatGPT Enterprise, PwC bought more than 100,000 ChatGPT Enterprise seats after launching ChatPwC and the UK government closed four internal AI pilots as superseded by widely available platforms. On chat, buying has already won. The credential and CI rows are the opposite: they run on systems you already operate, and no vendor can scope your credentials for you. CSA’s working rule for CI is to “treat every environment variable visible to an agent as exposed”.
Three conditions move the line. An estate on a single agent brand can lean harder on that vendor’s own admin controls and native spend caps. The case for one layer across agents starts with the second brand. Headless agents at fleet scale can justify building or forking a runtime. And a team that can’t ship emergency gateway upgrades and full credential rotations within days should license the data plane rather than self-host open source code that holds every key.
One picture across every agent: where Adversa AI fits
This is the layer we build. Adversa AI’s Coding Agent Security Platform is the buy side of that split: it watches what your coding agents do and stops the damage before it lands, whether that is a wiped database, leaked credentials or malicious code shipping to production. It covers the agents you’ve approved, across brands, on the machines where they run.
It sits next to what you built. One of its two components is a gateway, but it does a different job from your proxy. The Agent Security Gateway sits on the agents’ own traffic (LLM calls, responses, tool and MCP calls) and reads them for behavior. It runs inline, or reads from the gateway you already operate, so routing, keys and the spend ledger stay yours. The Endpoint Security Sensor runs on developer machines and watches the agent’s actions, strictly the agent’s and not the developer’s, across files, the shell and CI/CD. Harness hooks and direct integrations with the top vendors’ own compliance APIs add two more capture surfaces, so the records your vendors already keep land in the same place. Everything exports to the SIEM you already run, and deployment can be cloud or on-prem.
Those four surfaces feed one agent behavior graph: every step the agent reasons through and every action it takes, connected. That matters because coding agent attacks rarely look like attacks one step at a time. A poisoned repo or skill is installed, the agent acts on an attacker’s instructions, a secret is read, data leaves. Each step is routine on its own. The chain is the breach, and it is visible only where the surfaces meet. A hook integration alone sees one of those surfaces.
The detection content is the key feature you can’t easily build and maintain. Over 300 policies ship by default, covering every known coding agent attack technique and public incident, and our offense team keeps them current. What we break in the lab, the runtime blocks by default. However, when you need to tune policies for your own use cases, or to ship a new rule quickly, your own policies are written in plain English, and every generated policy is validated, simulated, versioned and approved before it goes live. Enforcement happens at the action level: warn, deny or human-in-the-loop.
In production, measured in October 2026, raw signals became confirmed incidents at a ratio of about 2,000 to one. One flagrant action gets blocked; one merely suspicious step gets remembered, not alerted. Blocking decisions take a median of 0.2 ms, and the design fails open: a crash never blocks a developer.
The first production deployment is the clearest test of the build vs buy argument, because the customer already ran an AI gateway, endpoint security and a SIEM:
Large financial institution, coding agents on macOS and Linux
A large financial institution routed its coding agents, Codex, Claude Code, and Copilot, through the platform on macOS and Linux developer machines. From day one the security team could see what each agent was actually doing: the commands it ran, the systems it touched, the data it moved. Developers noticed nothing, and work went on as before. Then, in the first week, the platform stopped a real attack. An agent absorbed a malicious skill and followed its hidden instructions: minutes later it read internal API secrets and tried to send them outside. The AI gateway, the EDR, and the SIEM had all seen nothing wrong, because every step looked routine on its own.
That is the trade we think the evidence supports. Keep the plumbing you built and own it well. Let a team whose whole job is coding agent attacks maintain the detection and the layer that connects every agent, vendor and model, so security can stop the damage, not the developers.
An AI coding agent security plan for the next 90 days
Whatever you decide to buy, most of this plan is work only you can do. It is ordered so that each phase removes a route around the next one.
Days 1 to 30: close the routes around your controls
- Inventory the agents you’ve approved and how each one reaches models. Note which honor a gateway base URL and which call home through the vendor’s own service.
- Pin the base URL in managed settings that projects cannot override, and block direct provider endpoints at the network edge.
- Push each vendor’s admin controls through MDM: bypass and auto modes off where the work allows, hooks and MCP servers restricted to managed lists, minimum version floors, sandbox deny rules for
~/.ssh and cloud credential files and a deliberate failure mode for each hook: closed where it is your only hard deny, open where another layer backs it up. Make sure developers are not local administrators, or the managed file becomes a suggestion.
- Add detection and policy enforcement at the endpoint for every agent you run, and make sure it correlates gateway events with what actually happens on the endpoint. A chain that starts in model traffic and ends in a shell command is invisible to either layer alone. If you buy a third-party solution, check these with any vendor, including us:
- Show one action chain reconstructed end to end across two agent brands on a developer machine.
- Can it read from the gateway we already run?
- Who writes the detection content, how often does it change, and which of the public 2026 incidents does it cover by default?
- What is the measured overhead on our traffic, and what happens to developers when the sensor fails?
- What would it have blocked during the pilot, and at what false positive rate?
Days 31 to 60: shrink the blast radius
- Remove production credentials from developer workspaces. Replace long-lived tokens with short-lived scoped ones, turn on deletion protection and move backups outside any account an agent can reach.
- Put agent configuration under code review: CODEOWNERS on
.claude/, .cursor/, .vscode/, AGENTS.md and their equivalents. Remove AI workflows that read untrusted issue or PR text while holding privileged tokens. Publish through OIDC and add a soak period before new package versions reach developers. Keep the rule GitHub applies to its own cloud agent: an agent never approves or merges its own PR.
- Harden your gateway as tier 0 infrastructure. Keep the admin plane off the user network, block test and debug endpoints upstream, don’t run the container as root, pull images by digest from a private mirror with delayed promotion and never deploy floating tags. Reconcile gateway spend against provider invoices, run synthetic budget and rate limit tests on every upgrade, and ship logs to your SIEM from the first day.
Days 61 to 90: protect the record and test what you run
- Make the audit trail tamperproof. Ship agent telemetry, hook events, compliance API exports and gateway logs to an append-only store outside the developer machine and outside any account an agent’s credentials can reach, so no agent, whatever its brand, can delete or rewrite the record of what it did. Enforce the exporters through managed settings so an agent can’t switch them off.
- Evaluate the solutions you already run, the gateway, EDR, SIEM and vendor controls, against the public 2026 incidents. Replay the chains in a test environment and record which layer saw each step and which one could have stopped it.
- Retest every control after every upgrade, yours and your vendors’. Silent failure is the dominant failure mode in this stack, so treat a control you haven’t tested since the last release as broken.
You approved the agents. Not every action they take. The controls that hold sit outside the agent’s loop, and that is where a coding agent security platform belongs: next to the gateway you built, across every agent brand you run, stopping the chain before the damage lands. The demo takes 30 minutes; if it fits, a scoped observe mode pilot follows.
Build vs buy for AI coding agent security: own the plumbing, buy the coherent picture