Skip to main content

11. Security & Ethics

AI Agent Security

AI agent security protects systems that can read untrusted content and take side-effecting actions: prompts, tools, data, memory, and outbound channels all become attack surfaces. Defense in depth combines identity, policy allowlists, sandboxes, HITL, and monitoring around every hop of the agent loop — not a single “safe prompt.” This module opens with the threat model and control map; later lessons deepen injection, privacy, authZ, tool safety, hallucinations, and governance.

What you will learn

  • Map agent-specific threat surfaces beyond chatbots
  • Apply defense-in-depth control layers
  • Gate ingress, tools, and egress in the agent loop
  • Prioritize HITL and least privilege for side effects
  • Answer interview questions with short, solid answers
Prompts tools data memory actions audit threat surfaces
Interview staple: agents are powerful because they act — that is also why they need harder controls.

Definition

AI agent security is the practice of reducing risk for systems that combine language models with tools, memory, and autonomy. Unlike a text-only chatbot, a compromised or misled agent can exfiltrate data, change systems, spend money, or spam users — so confidentiality, integrity, and availability must cover the whole loop.

Security here is mostly defensive engineering and governance: least privilege, isolation, policy gates, human oversight, and audit — not “jailbreak tips.”

Introduction

This lesson (#1 in Security & Ethics) opens Module 11 after Agent Communication Protocols. MCP and A2A expand connectivity; security decides what those wires are allowed to do.

Next: Prompt Injection Attacks (Direct and Indirect) — the primary way untrusted text steers agents.

Why agents change the risk

  • Tools turn model mistakes into real-world side effects
  • Untrusted web/docs/email enter the context window
  • Memory persists bad instructions across sessions
  • Multi-agent and protocol links widen the trust boundary
  • Users over-trust fluent but wrong or unsafe actions

Threat surfaces

  • Prompts - direct and indirect instruction injection
  • Tools - unauthorized or excessive side effects
  • Data - PII/secret leakage into logs, prompts, or peers
  • Memory - poisoning, over-retention, cross-tenant bleed
  • Actions - purchases, sends, deletes, deploys
  • Audit gaps - no replay when something goes wrong

Control layers

Stack controls; no single filter is enough.

Identity policy sandbox HITL monitor control layers
Policy without sandbox still fails; sandbox without audit still blinds you.
  • Identity - who is the user/agent/server; strong authN
  • AuthZ - scopes and roles for tools and data
  • Policy - allowlists, schemas, rate and cost budgets
  • Sandbox - isolate browsers, shells, and credentials
  • HITL - approve high-risk side effects
  • Monitor - detect anomalies; retain auditable traces

Secure agent loop

Put gates on every hop, including tool results that re-enter context.

Ingress plan tool egress audit secure loop
Egress redaction matters as much as ingress filtering.
  • Ingress - validate/segment untrusted user and retrieved content
  • Plan - constrain goals and disallowed action classes
  • Tool - allowlist, schema-validate args, HITL if risky
  • Egress - block secret/PII leakage in replies and writes
  • Audit - immutable traces of prompts, tools, and decisions
  • Stop - budgets and kill switches for runaway loops

Trust boundaries

  • User messages are untrusted
  • Web, email, PDFs, OCR, and tool outputs are untrusted
  • MCP servers and A2A peers need explicit admission
  • System/developer policy must stay non-overridable by content
  • Separate tenants and environments (dev vs prod)

Failure modes

  • Relying on “please ignore injections” prompts alone
  • Admin tools enabled by default for convenience
  • Logging raw prompts with secrets forever
  • No HITL on send/pay/delete/deploy
  • Shared credentials across all tools and tenants

Map to this module

  • Next: prompt injection deep dive
  • Then: privacy, access control, tool execution security
  • Later: hallucinations, responsible AI, secure deployment

Program / implementation notes

Write a one-page threat model for your agent: assets, actors, surfaces, controls. Mark each tool read vs write and whether HITL is required. Add a kill switch and max tool-call budget before any demo goes shared.

  • Start with deny-by-default tool allowlists
  • Next: Prompt Injection Attacks (Direct and Indirect)

Advantages and limitations

  • Advantage: structured controls scale better than hope
  • Advantage: HITL + allowlists stop many catastrophic actions
  • Advantage: traces enable incident response and eval
  • Limitation: models can still be socially engineered
  • Limitation: over-blocking hurts product usefulness
  • Limitation: security is continuous — not a one-time checklist

Key points

  • Agents add tool and memory risk beyond chatbots.
  • Threat surfaces: prompts, tools, data, memory, actions, audit.
  • Defense in depth: identity, policy, sandbox, HITL, monitor.
  • Gate ingress, tool calls, and egress every loop hop.
  • Deny-by-default allowlists and kill switches are baseline.
  • Untrusted content must not override system policy.

FAQs

Is a strong system prompt enough?

No. Prompts help but are bypassable. Enforce allowlists, sandboxes, schemas, HITL, and monitoring outside the model.

What is the highest-impact first control?

Usually deny-by-default tool allowlists plus HITL on irreversible writes (send, pay, delete, deploy).

How do protocols affect security?

MCP and A2A increase connectivity. Admit servers/peers explicitly and apply the same least-privilege and untrusted-output rules.

Chatbot security vs agent security?

Chatbots mainly risk bad or leaked text. Agents risk real side effects through tools, so authZ and action gates dominate.

Interview questions

  1. What makes AI agent security different from chatbot security?

    Answer Agents can take side-effecting tool actions and persist memory, so attacks can change systems or leak data — not just produce bad text.

  2. Name key agent threat surfaces.

    Answer Prompts/injection, tools, sensitive data, memory, high-impact actions, and missing audit trails.

  3. What control layers should you stack?

    Answer Identity/authZ, policy allowlists and budgets, sandboxes, HITL for risky actions, and continuous monitoring/audit.

  4. Where do you put gates in the agent loop?

    Answer On ingress content, before tool execution, on egress/output, plus budgets and a kill switch — with full traces.

  5. What should never be overridable by retrieved content?

    Answer System and developer policy: tool allowlists, safety rules, and authorization decisions must stay outside untrusted text.

  6. What is a practical baseline before shipping?

    Answer Deny-by-default tools, HITL on irreversible writes, secret redaction in logs, rate/cost budgets, and an emergency stop.

Related topics

Practice task

Complete each numbered practice step in a notebook or doc before opening the next lesson.

  1. List assets your agent can touch (systems, data classes, actions).
  2. Mark each tool as read or write and assign HITL yes/no.
  3. Write ingress, tool, and egress controls for one user journey.
  4. Define a kill switch and max tool calls per session.
  5. Answer interview questions 1, 3, and 4 in two sentences each.