Back to the curriculum

L3-M07 · Level 3 · ~15.5 h

Agent Safety and Security

What you build: Agent security test pack

lessons
5
lesson hours (estimate)
≈ 10 h
0/5 lessons marked done · Progress is saved in this browser only. No account, nothing is sent to a server.
In review. The curriculum, module overviews and Levels 1–3 lessons are drafts written with AI assistance and reviewed by AI. Human review is still pending. English translation: AI-assisted, not human-reviewed.

Levels 1–3 lessons, exercises and quizzes are published as drafts, in Vietnamese with an AI-assisted English translation. They may change after human review.

Module path

  1. Lesson 1 · L3-M07-L01≈ 2 h

    Chat and voice agent testing: interruptions, handoffs, escalation (multi-agent coordination as a short section)

    What you build: Conversation and handoff test cases

    Needs: L3-M03-L01, L3-M05-L03, L3-M05-L04

    Key terms (7)
    • Barge-in / interruptNgắt lời: người dùng nói đè khi agent đang phát; phần chưa phát bị bỏ
    • HandoffChuyển giao: chuyển cuộc trò chuyện cho một agent khác
    • EscalationLeo thang: chuyển cuộc trò chuyện cho một con người
    • Escalation accuracyĐộ chính xác leo thang: cặp (số ca leo thang đúng lý do, số ca cần leo thang)
    • Near miss (escalation)Ca suýt leo thang: ca kỳ vọng không leo thang dù người dùng nói chữ librarian/human/thủ thư
    • Conversation trace (lab)Bản ghi hội thoại: dãy sự kiện phẳng user/say/tool/handoff/escalate...; khác Trace (cây span) của L3-M01-L04
    • Segment / heardĐoạn nói / số đoạn đã phát (heard); heard=None nghĩa là phát hết
  2. Lesson 2 · L3-M07-L02≈ 2 h

    Indirect prompt injection through tool results and documents

    What you build: Injection-through-data suite

    Needs: L3-M07-L01, L1-M04-L04, L3-M02-L03

    Key terms (8)
    • Indirect prompt injectionInjection gián tiếp (chèn chỉ thị gián tiếp, glossary L3-M02-L03): chỉ thị nằm trong dữ liệu mà agent đọc
    • PlacementVị trí chèn: bản ghi mà dấu chèn được đặt vào (thân tài liệu, ghi chú sách, email, tiểu sử)
    • Benign utilityĐộ hữu dụng khi không bị tấn công: tác vụ ra kết quả đúng khi không chèn gì
    • Utility under attackĐộ hữu dụng dưới tấn công: tác vụ vẫn ra kết quả đúng, không thêm tác động nào, khi bị chèn
    • Followed / Targeted ASRMục tiêu kẻ tấn công thật sự xảy ra (tỷ lệ tấn công thành công)
    • Attempted (blocked)Đã thử nhưng bị chặn: agent làm theo dữ liệu, một kiểm soát khác dừng hậu quả; vẫn phải báo
    • Exfiltration (lab)Exfil: email tới người nhận ngoài miền cho phép, hoặc mang bí mật tới bất kỳ ai
    • Canary markerDấu canary lành tính (ví dụ BANANA) do harness phát hiện
  3. Lesson 3 · L3-M07-L03≈ 2 h

    Excessive agency and permission boundaries

    What you build: Permission matrix tests

    Needs: L3-M07-L02, L3-M01-L01, L3-M01-L05, L3-M02-L03

    Key terms (8)
    • Excessive agencyQuyền tự quyết thừa (glossary L3-M01-L01); bài này kiểm gốc rễ quyền thừa
    • Excessive permissionsQuyền thừa: tool có quyền trên hệ thống phía dưới rộng hơn mức cần
    • Least privilegeĐặc quyền tối thiểu: chỉ cấp quyền đúng mức cần
    • Permission matrixMa trận phân quyền: vai × tool × lớp tài nguyên
    • Resource classLớp tài nguyên: quan hệ giữa mục tiêu và người gọi (self/class/other, internal/external...)
    • Expected n/a cellÔ n/a đã khai: ô không có dữ liệu mẫu, ghi trong spec kèm lý do
    • Complete mediationCưỡng chế đầy đủ: kiểm quyền ở hệ thống phía dưới trên mọi lời gọi, không giao cho model
    • Confused deputyĐại biểu bị lừa: dùng một danh tính quyền cao để làm thay một bên quyền thấp
  4. Lesson 4 · L3-M07-L04≈ 2 h

    Human-in-the-loop approval and side-effect controls

    What you build: Approval-gate tests

    Needs: L3-M07-L03, L3-M02-L04, L3-M01-L05, L3-M06-L02

    Key terms (8)
    • Human-in-the-loop approvalPhê duyệt có con người: một người đồng ý trước một hành động rủi ro cao
    • Approval gateCổng duyệt: gắn một phê duyệt với một lời gọi (tool, tham số, một lần, hết hạn) và một người duyệt hợp lệ
    • DigestBăm tham số chuẩn tắc, để biết lời gọi thực thi đúng là lời gọi đã duyệt
    • Structured displayHiển thị có cấu trúc: `tool(khóa="giá trị", ...)`, đọc lại được để so bằng từng trường
    • TTL (time to live)Hạn dùng: phê duyệt chỉ dùng được trong một số lượt sau khi quyết, theo đồng hồ của cổng
    • Self-approvalTự duyệt: một bên của lời gọi (agent yêu cầu, danh tính lời gọi chạy bằng, người được lợi) quyết; bị chặn bằng `SELF_APPROVAL` (khác confused deputy của L03)
    • Rubber stampNgười duyệt bấm đồng ý mà không đọc hiển thị
    • Side-effect auditRà sổ tác động: tìm tác động rủi ro cao thiếu phê duyệt hợp lệ
  5. Lesson 5 · L3-M07-L05≈ 2 h

    Red-teaming an agent safely

    What you build: Scoped red-team plan and findings

    Needs: L3-M07-L02, L3-M07-L03, L3-M07-L04

    Key terms (8)
    • Red-teamingThăm dò đối kháng có cấu trúc để tìm điểm yếu
    • ScopePhạm vi: cái được chạm và không được chạm (danh sách cho phép)
    • Rules of engagementQuy tắc thực hiện: cách thăm dò (sandbox, dấu lành tính, không mạng)
    • Stop conditionsĐiều kiện dừng: khi nào ngừng thăm dò
    • Written authorisationCho phép bằng văn bản: chủ hệ thống đồng ý trước, trong một khung thời gian
    • FindingPhát hiện: một lỗ hổng, có công thức tái lập, tác động và mức độ
    • ReproduceTái lập: chạy lại công thức trong sandbox mới, xác nhận tác động đã khai còn đó
    • Release candidate (`rc`, lab)Cấu hình gộp bốn điểm yếu của module, mục tiêu red-team của bài

A. Module overview

Field Value
Module ID L3-M07
Level 3 - AI Agent Quality Engineer
Description Testing what an agent with side effects can do that it must not do, in five places: chat and voice conversations (interruptions, handoffs, escalation, with voice simulated as turn events with a barge-in marker), indirect injection through tool results and documents (detected by a state diff of the environment, not by the agent's words), excessive agency (a role × tool × resource-class matrix of every role checked against a spec written beforehand, least privilege, the confused deputy), human-in-the-loop approval (one approval bound to one call and a valid approver, enforcement and the clock in the downstream system, an audit of the side-effect ledger) and safe red-teaming (scope, rules of engagement, stop conditions, written authorisation, reproducible findings). The module's lab is the simulated assistant of the fictional product ThuVien Mini (a school library helper): a rule-based program, not a language model, with ten weaknesses and two defences switched on by name, in a sandbox where every tool is an in-memory fake; deterministic, offline, no model call, no network, no API key. Every injected marker is benign (a canary, an email to example.invalid) and aimed only at the lab's fake agent. What is known about injection, permissions, approvals, conversations and red-teaming is cited from 15 sources read on 2026-11-05: two OWASP pages (LLM01, LLM06), three arXiv papers (Greshake et al., AgentDojo, Microsoft's lessons from red-teaming 100 products), NIST's GenAI profile (AI 600-1), Microsoft's red-team planning guide, three Anthropic pages, four OpenAI pages and the MITRE ATLAS data. How far each source was read is recorded in references.md and in §12 of each lesson.
Why this module matters An agent that calls tools can send an email, delete a record, clear a fine or borrow a book for someone else. Safety bugs do not show in a correct answer: a "yes" said before the question finished playing still causes an effect, a document holding an instruction makes the agent do what the user never asked, a service identity with wide rights bypasses the rule "see only your own record", one approval is reused for a second call. A tester needs to measure consequences in the state and the side-effect ledger, know what a defence lets through, and record a finding someone else can re-run. The module lays the ground for the capstone (L3-M08), where the security test pack is part of the agent testing framework.
Target professional skill Level 3: testing the safety and security of an agent with side effects in a sandbox, with conversation and handoff test cases, an injection-through-data suite with benign utility and utility under attack, a permission matrix and confused-deputy probes, approval-gate tests with a side-effect audit, and a scoped, reproducible red-team record. The module attacks no real system, evaluates no vendor's model or product and does not teach how to write a real attack.
Estimated time 5 lessons (120 + 120 + 120 + 120 + 120 minutes) = 10 hours, plus the quiz (~0.5 hour) and the module assignment (~5 hours) = ≈ 15.5 hours for someone who has finished L3-M06. An estimate, not measured with real learners.
Prerequisites L3-M06 (L04 needs L3-M06-L02). The module reuses, without repeating: fake tools and the sandbox, the side-effect log (L3-M02-L03, L3-M02-L04), task scenarios and end-state oracles (L3-M03-L01), multi-turn conversation regression (L3-M05-L03), idempotency keys bound to the operation (L3-M06-L02), gates that only label and reports traceable to data (L3-M06-L05), consequence oracles independent of the filter (L1-M04-L04), mutation testing (L3-M03-L03). No API key needed.
Module output (deliverable) An agent security test pack: conversation and handoff test cases, an injection-through-data suite, a permission matrix with probes, approval-gate scripts with an audit, a cleaned red-team record, a scorecard of eight release candidates with a gate the learner writes, and a golden table for mutation testing; plus the small product of each lesson
Cost 0

What the learner builds. Step by step, in code-labs/l3-m07: (L01) a new suite of conversation cases that the lab's gate confirms catches all five weaknesses of the lesson, and a function that finds the configurations that suite catches; (L02) a prediction of one task's outcomes under two defences, an exfil detector that reads only the World's state, and a new task for the injection suite; (L03) a fix of an over-broad policy, the list of its excess grants, spec rows written from a user story, and a measurement of the confused-deputy gap; (L04) a prediction of the audit of six runs, an approver that compares every field, and four approval-gate test cases (skip, reuse, expiry, self-approval); (L05) the scope, rules and stop conditions of a red-team plan, a new finding that reproduces, and an honest record of an over-claimed finding. The lab imports nothing from earlier labs and needs only pytest.

What the module does not do. It calls no model, measures no real model, agent or product, and ranks or recommends no tool or provider: every number of the lab describes a rule-based program. The lab's agent recognises intents with regular expressions; "following instructions found in data" is a weakness switched on by name, not the behaviour of a model. Voice is only turn events with a barge-in marker: there is no audio. Multi-agent work is only a short section of L01 (two internal agents to test handoffs). There is no real attack, no network and no file outside the Python process; every marker is benign and detected by the harness, not a usable attack. Red-teaming targets only the lab's own simulated agent, with a scope written beforehand. No automated workflow is created or changed in the repository. Every gate only marks HOLD or READY_FOR_REVIEW, fails closed on missing or broken data and never says "approved"; a person writes the spec before the run, decides and is accountable for every real effect.

Terms reused with another meaning (each lesson has a sentence that separates them). handoff hands the conversation to another agent, escalation hands it to a human (L01); followed means the attacker's goal really happened in the World, unlike reached (the goal sentence got to the agent) and unlike attempted_blocked (the agent tried and another control stopped it: still reportable) (L02); "allowed" in the matrix means authorization let the call through, even when the call then stops at the approval gate or hits a business error (L03); an approval in L04 is a person's decision for one call, unlike a gate's READY_FOR_REVIEW, which only says "a person should read this"; a red-team finding (L05) is a weakness that reproduced, unlike a failing test.

B. Learning objectives

ID Objective
MO1 Design conversation test cases for interruptions, handoffs and escalation (including a near-miss case and a voice case with a barge-in), and read a conversation trace to see which segments were played, who holds the conversation and what a handoff payload carries.
MO2 Build an indirect-injection suite (task × goal × variant) that detects consequences with a state diff, report both the followed rate and utility under attack, and show what a defence lets through.
MO3 Write permission spec rows from a user story, check a policy with a role × tool × resource-class matrix of every role, find excess and missing grants, and measure the confused deputy with the same call run in the user's context and as the service identity.
MO4 Write tests for a human-in-the-loop approval gate (one approval for one call, same arguments, once, in time, the right approver), compare enforcement in the World with enforcement in the agent, and use an audit of the side-effect ledger instead of the agent's words.
MO5 Write a red-team plan with scope, rules of engagement and stop conditions for the simulated agent, record findings that reproduce, and state what a READY_FOR_REVIEW test pack or record does not prove yet.

C. Lessons

ID Lesson Duration Prerequisites Concepts Practical output
L3-M07-L01 Chat and voice agent testing: interruptions, handoffs, escalation 120' L3-M03-L01, L3-M05-L03, L3-M05-L04 three risky joints, voice simulated as turn events and heard, the conversation trace, five weaknesses, the always-on checks, escalation accuracy, a gate that re-runs on each weakness; multi-agent coordination as a short section Conversation and handoff test cases
L3-M07-L02 Indirect prompt injection through tool results and documents 120' L01, L1-M04-L04, L3-M02-L03 instructions inside data, placements, goals and variants, check_followed as a state diff (exfil: any recipient outside the domain), the attempted_blocked outcome, a keyword screen and a tool filter, benign utility and utility under attack Injection-through-data suite
L3-M07-L03 Excessive agency and permission boundaries 120' L02, L3-M01-L01, L3-M01-L05, L3-M02-L03 excessive permissions (recap of L3-M01), least privilege, complete mediation in the World, resource classes relative to the caller, the matrix of every role and declared n/a cells, excess, the confused deputy Permission matrix tests
L3-M07-L04 Human-in-the-loop approval and side-effect controls 120' L03, L3-M02-L04, L3-M01-L05, L3-M06-L02 an approval bound to one call (digest), single use, TTL on the gate's own clock, a valid approver and self-approval, a structured display, failing closed, enforcement in the World or in the agent, the side-effect audit, a misleading display Approval-gate tests
L3-M07-L05 Red-teaming an agent safely 120' L02, L03, L04 red-teaming versus benchmarking, the rc configuration, scope (an allowlist), rules of engagement, stop conditions, written authorisation, an impact that matches the recipe, "attempted but blocked", a required summary, the limits of red-teaming Scoped red-team plan and findings

D. Practical work (module assignment)

The module assignment exercises.en.md: an agent security test pack for the ThuVien Mini v2 assistant on new data (nine conversation cases and six broken ones, a 60-case corpus with the canary MANGO and three new variants, the policy v2 with five changes and seven broken edits, three permission probes, five approval scripts with an expected ledger, a red-team plan with five broken edits and seven findings, eight release candidates): conversations, injection, permissions, the approval gate, red-teaming and a scorecard with a gate the learner writes, a golden table and mutations, reproduction; a fixed interface with module-style calls, acceptance criteria AC1-AC7 and a 100-point rubric; plus a standalone challenge on the lab's data. The five standalone exercises of the lessons are in code-labs/l3-m07/exercises/ and in §9 of each lesson: a new suite of cases that catches five weaknesses and a weakness finder (L01), a prediction of outcomes under two defences, an exfil detector that reads the World and a new task (L02), a fix of an over-broad policy, its excess grants, a spec written from a user story and a confused-deputy measurement (L03), an audit prediction, an approver that compares every field and approval-gate test cases (L04), a plan, a new finding and an honest record of an over-claimed finding (L05).

E. Module assessment

The module quiz quiz.en.md (12 questions, 20 points, pass mark 70%), and the module assignment with acceptance criteria and a rubric (exercises.en.md); the solutions and the instructor guide are for instructors only. Each lesson's practice is practice-01.md to practice-05.md, public and with reference solutions. The instructor's solutions and tests are in code-labs/l3-m07/instructor/ and are for instructors only.

F. References

The shared list is references.md (15 sources fetched on 2026-11-05, with the access date and how far each was read). Each lesson also has its own reference table in §12.

Objective ↔ assessment matrix

Objective Lesson Standalone exercise (§9) Quiz questions Module assignment criteria
MO1 L01 exercises/test_l01_conversation.py Q1, Q6 AC1 (and AC6, AC7 for the whole module)
MO2 L02 exercises/test_l02_injection.py Q2, Q9 AC2 (and AC6, AC7 for the whole module)
MO3 L03 exercises/test_l03_permissions.py Q3, Q7, Q10 AC3 (and AC6, AC7 for the whole module)
MO4 L04 exercises/test_l04_approval.py Q4, Q8, Q11 AC4 (and AC6, AC7 for the whole module)
MO5 L05 exercises/test_l05_redteam.py Q5, Q12 AC5 (and AC6, AC7 for the whole module)