Shifting Security Left with Threat Modeling and the AI Red Teaming Agent
This lesson covers threat modelling for agents, secure development practices and automated adversarial testing with the AI Red Teaming Agent in Foundry, which move security analysis and testing into design, development and the CI pipeline.
Learning outcomes
After completing this lesson, you will be able to:
- Identify the main threats to multi-agent systems.
- Build shift-left practices into the development workflow.
- Run automated adversarial tests with the AI Red Teaming Agent.
Threat modelling agent systems
Threat modelling identifies how a system could be attacked before it is built. For multi-agent systems, the main threats are listed below; each maps to controls covered elsewhere in the course.
- Direct prompt injection (jailbreaks) by users trying to bypass instructions.
- Indirect prompt injection through documents, web pages, emails and tool results.
- Excessive agency: agents with more tools, permissions or autonomy than needed.
- Data exfiltration through tool arguments, generated links or outputs.
- Memory poisoning: malicious content stored and reused by other agents.
- Supply chain: compromised MCP servers, packages or models.
Name the threat
Secure development practices
Shift-left practices are built into the development workflow: secure templates and dev containers with keyless authentication by default; secret scanning and push protection in the repository; dependency and container image scanning; infrastructure-as-code checks against policy; code review checklists for tools (input validation, least privilege, idempotency); and security evaluations that run in CI and block merges or releases when thresholds are breached.
Shift-left practices
The AI Red Teaming Agent
The AI Red Teaming Agent in Foundry automates adversarial testing. It generates attack objectives across risk categories (such as violence, hate and unfairness, sexual content, self-harm, and, for agents, risks like prohibited actions and sensitive data leakage), transforms them with attack strategies from Microsoft's open-source PyRIT framework (for example Base64 or other encodings, character manipulation, flipping, jailbreak templates and multi-turn crescendo attacks, grouped as easy, moderate and difficult), sends them to the target and evaluates the responses. The key metric is the attack success rate (ASR), the share of attacks that produced an undesirable response.
from azure.ai.evaluation.red_team import RedTeam, RiskCategory, AttackStrategy
red_team = RedTeam(azure_ai_project=PROJECT_ENDPOINT, credential=credential,
risk_categories=[RiskCategory.Violence, RiskCategory.HateUnfairness],
num_objectives=10)
result = await red_team.scan(target=call_agent, # callback that sends a prompt to the agent
scan_name="claims-agent-v14",
attack_strategies=[AttackStrategy.EASY, AttackStrategy.MODERATE, AttackStrategy.Base64])Scans run locally with the Azure AI Evaluation SDK during development, or as cloud runs against Foundry agents and model deployments; results appear in the Foundry portal, where ASR can be compared across versions. Running scans in CI for every significant change, with an ASR threshold as a gate, is the shift-left use of the tool.
Attack success rate
Security at the end
A team plans a manual penetration test two weeks before launching a multi-agent assistant. In the previous project, the test found prompt injection issues that delayed launch by two months.
Shift left: threat-model the agents and tools at design time, run AI Red Teaming Agent scans in the CI pipeline from the first working version with an attack success rate threshold, and keep the manual test as a final check. Issues are then found when they are cheap to fix rather than at the end.
How can red teaming become part of every release?
Show answer
Run the AI Red Teaming Agent's scans in CI and fail the build when the attack success rate exceeds a threshold.
Exam Tips
Remember for the exam
- Threat-model injection, excessive agency, exfiltration, memory poisoning and supply chain.
- AI Red Teaming Agent: risk categories, PyRIT attack strategies, attack success rate.
- Run red-team scans in CI with an ASR threshold as a gate.