Sunday, April 5

Security Engineer Agent for Claude Code: Automate Your Security Infrastructure

Security work is fundamentally reactive in most engineering organizations. A vulnerability surfaces, someone files a ticket, the on-call engineer context-switches from whatever they were doing, spends 45 minutes reconstructing the threat model, and then starts actually fixing things. Compliance audits follow a similar pattern — frantic documentation sprints, manual evidence collection, and the uncomfortable realization that half your infrastructure isn’t where you thought it was.

The Security Engineer agent for Claude Code changes this dynamic. Instead of treating security as a specialized knowledge silo that slows down feature delivery, you get a persistent, context-aware security collaborator that proactively identifies problems, generates production-grade security infrastructure as code, and guides compliance work with the depth of someone who has actually implemented SOC2 controls before. It doesn’t replace your security team — it eliminates the friction between good intentions and actual implementation.

If you’re a senior developer who’s ever stared at a blank Terraform file trying to remember the exact structure of a least-privilege IAM policy, or who has spent a sprint just wiring up CloudTrail and GuardDuty before getting to any real work, this agent addresses exactly that tax.

When to Use the Security Engineer Agent

This agent is designed to be used proactively, not just as a break-glass resource when something is already broken. The description explicitly flags this. Here are the scenarios where it pays off immediately:

Greenfield Infrastructure with Compliance Requirements

You’re building a new service that will handle payment data or PHI. Before you write a single line of application code, the Security Engineer agent can help you establish a security baseline — KMS key configuration, VPC flow logs, encryption settings, IAM boundaries — so you’re not retrofitting security controls after the fact.

Pre-Audit Readiness

SOC2 Type II audits require continuous evidence. If you’re 60 days out from an audit and your compliance automation is still largely manual, use this agent to design and implement automated control monitoring. It understands the specific control families for SOC2, PCI-DSS, HIPAA, and GDPR, not just general security principles.

Dependency Vulnerability Management

You’ve run a SAST or dependency scan and you have 200 findings ranked by severity. The agent can help you triage, contextualize findings against your specific architecture, and draft remediation plans that are actually implementable rather than generic security advice.

Incident Response Preparation

Most teams have no documented incident response runbooks until they need them. Use the agent to build threat detection rules, alerting pipelines, and automated response playbooks before an incident happens — not while one is in progress.

Security Reviews for Pull Requests

Drop the agent into your review workflow for any PRs touching IAM policies, network configuration, secrets handling, or authentication logic. It can catch misconfigurations that are easy to miss in standard code review.

Real-World Examples

Scenario 1: Setting Up a Security Baseline for a New AWS Account

A developer is spinning up infrastructure for a new product line that will eventually need SOC2 compliance. They need to establish foundational security controls before any workloads go live.

Developer: We're setting up a new AWS account for our payments service. 
           It needs to be SOC2 compliant eventually. Where do we start?

Agent: Start with the mandatory observability and detection layer before 
       any workloads touch this account. You need CloudTrail with 
       multi-region coverage writing to an S3 bucket with MFA delete 
       enabled, AWS Config with the SOC2 conformance pack deployed, 
       GuardDuty enabled across all regions, and Security Hub aggregating 
       findings. I'll generate the Terraform module for this baseline. 
       The KMS key needs rotation enabled and a policy that explicitly 
       grants access to the relevant AWS services without using wildcards 
       in the principal. After the detection layer, we'll define your IAM 
       permission boundaries so no role in this account can exceed them, 
       even if someone grants overly broad policies later.

Developer: What about secrets management?

Agent: For a payments context, you want AWS Secrets Manager with automatic 
       rotation enabled, not SSM Parameter Store — the audit trail 
       is cleaner for PCI-DSS. Every secret should be encrypted with a 
       dedicated KMS key, not the AWS-managed default. Set resource policies 
       on the secrets to restrict access to specific IAM roles, and enable 
       CloudWatch alarms on GetSecretValue calls from unexpected principals. 
       I'll include that in the baseline module.

Scenario 2: Responding to a Critical Vulnerability Finding

A developer is reviewing a dependency scan output and finds a critical CVE in a library handling authentication tokens.

Developer: Our SAST scan flagged CVE-2024-XXXX in our JWT library. 
           It's rated critical. How bad is it actually for our setup?

Agent: The exploitability depends on your specific usage. Tell me: are 
       you validating the algorithm field in incoming tokens, or are you 
       trusting the header claim? The most common exploits for JWT libraries 
       involve algorithm confusion attacks — accepting "none" as a valid 
       algorithm, or accepting RS256 tokens validated against an HMAC 
       secret. Pull up wherever you call the verification function and 
       show me the options you're passing.

Developer: Here's the code: [pastes code]

Agent: You're explicitly specifying the allowed algorithms, which mitigates 
       the primary attack vector. However, you're not validating the "iss" 
       claim, which means any token signed with your secret is valid 
       regardless of issuer. For the library vulnerability specifically, 
       update to version 9.x immediately — the patch is non-breaking for 
       your usage pattern. For defense in depth, add issuer validation and 
       pin the expected issuer value in your config. Also add token 
       binding to your session store so stolen tokens can't be replayed 
       from different IPs. I'll write the updated configuration.

What Makes This Agent Powerful

Production-Grade Security as Code

The agent’s system prompt is built around infrastructure as code patterns — specifically Terraform. When it recommends KMS encryption, it doesn’t just say “encrypt your data.” It generates the KMS key resource with rotation enabled, the correct key policy, and the service principal grants for S3, RDS, and CloudWatch Logs. This is implementation-ready output, not advisory output.

Compliance Framework Awareness

The agent understands the specific control requirements for SOC2, PCI-DSS, HIPAA, and GDPR as discrete, implementable controls — not just as abstract principles. When you’re targeting a specific compliance framework, it can map infrastructure decisions to specific control requirements and help you build automated evidence collection.

Zero Trust Architecture Guidance

The agent’s architecture principles are grounded in zero trust — never trust, always verify, least privilege. This means IAM recommendations won’t use wildcards, network designs will default to deny, and secret access will be explicitly scoped. These aren’t just best practices it mentions; they’re constraints it applies when generating any infrastructure code.

Defense in Depth Thinking

Single-layer security recommendations are a red flag in any security architecture. This agent naturally layers controls — encryption at rest plus in transit plus key management plus access logging. When you ask about one security concern, it surfaces adjacent concerns in the same domain without requiring you to ask follow-up questions.

Automation-First Posture

Manual security controls fail at scale. The agent defaults to automated solutions — automated rotation, automated detection rules, automated incident response playbooks. When it can’t automate something, it tells you explicitly and explains why human-in-the-loop is required for that specific control.

How to Install the Security Engineer Agent

Installing this agent takes under two minutes. Claude Code automatically discovers sub-agents stored in your project’s .claude/agents/ directory and makes them available as specialized personas during your sessions.

First, create the agents directory if it doesn’t already exist:

mkdir -p .claude/agents

Next, create the agent file:

.claude/agents/security-engineer.md

Paste the full system prompt — starting from “You are a security engineer specializing in infrastructure security…” — as the contents of that file. Save it. That’s the entire installation. The next time you open Claude Code in that project, the Security Engineer agent will be available and Claude Code will load it automatically.

To invoke it, reference it explicitly in your prompt: “Using the security engineer agent, review this IAM policy” or simply describe a security task and Claude Code will route to the appropriate specialist agent. You can scope this agent to a single project by placing it in that project’s .claude/agents/ directory, or make it globally available by placing it in your home directory at ~/.claude/agents/security-engineer.md.

Practical Next Steps

Install the agent today and point it at something concrete. If you have an existing AWS account, ask it to audit your current GuardDuty and Security Hub configuration and identify gaps. If you’re starting new infrastructure, ask it to generate a security baseline Terraform module scoped to your compliance target. If you’re mid-sprint, drop in a recent dependency scan output and have it help you triage.

The compounding value shows up over time — as the agent builds context about your specific architecture, your compliance targets, and your existing controls, its recommendations get progressively more precise. Treat it like a security-focused pair programmer who’s read your entire infrastructure codebase, not like a chatbot you query for generic advice.

Security debt is cheap to accumulate and expensive to pay down. An agent that makes the right security decisions easier than the wrong ones is one of the highest-leverage tools you can add to your development workflow.

Agent template sourced from the claude-code-templates open source project (MIT License).

Share.
Leave A Reply