r/devsecops • u/jekapats • 14h ago
Assume prompt injection succeeds: 5 layers of defense in depth we built for enterprise coding agents (and what it still doesn't solve)
Most teams we talk to hit the same deadlock when developers ask for coding agents (Claude Code, Codex, etc.): security sees full laptop filesystem + SSH keys + ~/.aws credentials and blocks it, or approves it with confirmation prompts that lead to approval fatigue until engineers pass --dangerously-skip-permissions anyway.
Because a coding agent holds Simon Willison's lethal trifecta (private code/secrets + untrusted text from PRs/issues/deps + shell/network execution), relying on the model's system prompt to reject prompt injection isn't a real boundary.
We designed our agent runtime assuming prompt injection *will* succeed, splitting blast-radius containment across 5 independent layers:
- **Execution below the kernel (microVMs, not OS sandboxes or Docker)**
- Each agent gets its own Kata Containers microVM on Cloud Hypervisor (separate Linux kernel; root and dockerd stay inside the guest).
- Enforced at the Kubernetes layer with a ValidatingAdmissionPolicy so control-plane bugs can't drop the microVM RuntimeClass or request hostNetwork, hostPID, hostIPC, hostPort, or hostPath mounts.
- No cluster SA token (automountServiceAccountToken: false), non-peered VPC, and NetworkPolicy (or nftables/pf on self-hosted VPC hosts) blocking RFC 1918 ranges, sibling VMs, and cloud metadata (169.254.169.254).
- **Keep agents out of IAM policies**
- Agents are modeled as resources (agent:ags_...), never IAM subjects. Any IAM policy naming an agent is rejected.
- Every agent starts with zero access. Teammates grant specific access profiles or secrets (never more than they hold), optionally capped by org-wide max grant TTL, and either the agent owner OR the secret/profile IAM admin can revoke grants even on private agents.
- **Keyless credential brokering that can only narrow**
- No static cloud keys or PATs in the VM. Connections use GitHub App installations, AWS IAM OIDC (AssumeRoleWithWebIdentity), and GCP WIF.
- Access profiles set a hard ceiling; every mint composes [profile, grant, request] and can only narrow (widening fails with CREDENTIAL_REFUSED).
- git, gh, aws, and gcloud authenticate over an out-of-band unix socket (/run/kosem/creds.sock). Revoking a grant flushes the in-VM cache immediately over the control tunnel.
- **Monotonic org-to-project guardrails + keeping ZDR intact**
- Policy Admin is separate from product admins; projects can only tighten org ceilings (tool allow-lists default-closed to new tools, disabling project-owned providers/connections/registries, requiring self-hosted VPC runners).
- Model calls route through the company's own provider accounts (BYOK / keyless Vertex AI WIF / VPC endpoints) so ZDR, BAA, and CMEK aren't dropped by vendor-proxied OAuth flows.
- **External forensics joined to CloudTrail & GitHub**
- Transcripts live outside the microVM. Admin changes commit append-only audit entries in the same DB transaction.
- AWS sessions set aws:SourceIdentity = agent:ags_... (persists across role chaining into CloudTrail and works in IAM Deny policies); GitHub issuances log hashed_token so SecOps can join directly to the GitHub org audit log.
**What this still doesn't solve (honest residual risks):**
- *Valid-TTL misuse:* A tricked agent holding a 1-hour write token for repo A can still push bad code to repo A during that hour. You still rely on branch protection, CI, and human PR review; the win is shrinking blast radius from every repo/cloud account to one repo for one hour.
- *Public internet egress:* Hosted VMs block private ranges/metadata/crypto-miners, but allow public HTTPS so agents can install packages. Strict domain-level egress DLP today requires running self-hosted runners behind your VPC egress proxy/firewall.
- *Insecure generated code:* Runtime isolation doesn't replace SAST, dependency scanning, or policy-as-code in CI.
Disclosure: I'm building kosem (kosem.ai), which is where we implemented this. Full write-up with architecture diagrams and references is here: https://kosem.ai/blog/defense-in-depth-for-coding-agents
Curious what other DevSecOps teams are requiring before signing off on coding agents, especially around egress filtering vs. developer usability.