AI Agent Safety: Prompt Injection & Guardrails | Stanford CS329Z Lecture 14 with Diyi Yang
Browse Stanford's online courses in Agentic AI: https://stanford.io/4AIRb2zWhat can go wrong when AI agents get access to your tools and data? In this Stanford CS329Z: Engineering AI Agents lecture, Stanford professor Diyi Yang covers the privacy risks of tool access, prompt injection (including indirect injection), red-teaming, sandboxing and permission models, output guardrails, responsible deployment, and human-in-the-loop design patterns.
Key questions answered in this lecture:
Q: What is indirect prompt injection in AI agents?
A: The agent reads untrusted content an attacker controls, such as a web page or email. Because the model sees everything as text in one context, it can't reliably tell the user's instructions from injected ones.
Q: How should AI agents be designed to resist prompt injection?
A: Diyi recommends constraining the system by design rather than relying on the system prompt. In the dual-LLM pattern, the model with tool access never reads untrusted data, and the model that reads it has no tools.
Q: Is sandboxing enough to make an AI agent safe?
A: No. Sandboxes are worth using and useful for monitoring behavior, but agents can find ways around them, and in her words, a sandbox does not equal real-world deployment.
Q: What privacy risks come with giving agents tool access?
A: Agents with access to messages and email can leak private details while trying to be helpful. Models recognize privacy norms when asked directly but often break them during tasks; contextualized guidance works better than blunt filters.
Q: When should a human stay in the loop for agent actions?
A: Asking the user before risky actions like deletion works for single actions, but breaks down when an agent takes a thousand steps. Diyi calls human-in-the-loop a nice vision that often falls short in practice.
Q: What is reward hacking in AI agents?
A: The agent maximizes the reward as written rather than the intended task, for example by special-casing tests. On benchmarks where honest success is impossible, models often game the tests instead of reporting failure.
Chapters:
0:00 Introduction: Safety Risks for AI Agents
1:27 Case Studies: Agent Accidents vs. Attacks
8:13 Why Agents Change the Risk Picture
11:06 Threat Modeling and the STRIDE Checklist
14:28 Q&A: Sandboxes, Reward Hacking, Message Boards
17:09 Agent Accidents: Reward Hacking
23:51 Wrong Actions: Overeager Agents, Privacy Leaks
30:48 Wrong Context and Wrong Reports
39:58 Prompt Injection and Indirect Injection
51:30 Misuse and Misalignment in AI Agents
57:12 Emergent Collusion Among Multiple Agents
1:05:22 Defenses, Guard Models, and Adaptive Attacks
1:08:28 Secure Design Patterns: Plan-Execute, Dual LLM
1:14:00 Risk Discovery, Monitoring, and Open Problems
About the speaker:
Diyi Yang is an assistant professor in the Computer Science Department at Stanford University, affiliated with the Stanford NLP Group, Stanford HCI Group, and the Stanford Institute for Human-Centered AI (HAI). Her research focuses on human-centered LLMs and human-AI interaction. She is a recipient of IEEE “AI 10 to Watch” (2020), a Microsoft Research Faculty Fellowship (2021), an NSF CAREER Award (2022), and a Sloan Research Fellowship (2024).
Readings:
- Shao et al., “PrivacyLens: Evaluating Privacy Norm Awareness of LMs in Action,” NeurIPS Datasets & Benchmarks (2024)
- Zhang & Yang, “Searching for Privacy Risks in LLM Agents via Simulation,” arXiv (2025)
- Li, “Agentic LLMs as Powerful Deanonymizers,” arXiv (2026)
Course website: https://cs329z.stanford.edu/
Watch the full CS329Z playlist: https://youtube.com/playlist?list=PLPRcF5HR02_U&si=3Z4OYphngcmQ0GIy
Recorded 11/18/2026 in CS329Z: Engineering AI Agents, a graduate course at Stanford University taught by Diyi Yang, Michael Ryan, and John Yang.
#AISafety #AIAgents #PromptInjection Receive SMS online on sms24.me
TubeReader video aggregator is a website that collects and organizes online videos from the YouTube source. Video aggregation is done for different purposes, and TubeReader take different approaches to achieve their purpose.
Our try to collect videos of high quality or interest for visitors to view; the collection may be made by editors or may be based on community votes.
Another method is to base the collection on those videos most viewed, either at the aggregator site or at various popular video hosting sites.
TubeReader site exists to allow users to collect their own sets of videos, for personal use as well as for browsing and viewing by others; TubeReader can develop online communities around video sharing.
Our site allow users to create a personalized video playlist, for personal use as well as for browsing and viewing by others.
@YouTubeReaderBot allows you to subscribe to Youtube channels.
By using @YouTubeReaderBot Bot you agree with YouTube Terms of Service.
Use the @YouTubeReaderBot telegram bot to be the first to be notified when new videos are released on your favorite channels.
Look for new videos or channels and share them with your friends.
You can start using our bot from this video, subscribe now to AI Agent Safety: Prompt Injection & Guardrails | Stanford CS329Z Lecture 14 with Diyi Yang
What is YouTube?
YouTube is a free video sharing website that makes it easy to watch online videos. You can even create and upload your own videos to share with others. Originally created in 2005, YouTube is now one of the most popular sites on the Web, with visitors watching around 6 billion hours of video every month.