AI security: secure and test LLM apps and agents

Stage 2 · Lesson 4 of 7

The agent loop as an attack surface

How LLM apps and agents work, and where they break

An runs a loop: the model reads the context, asks for a tool call, your code runs it, the result goes back into the context, and the loop repeats until the task is done. Each turn of the loop is a new chance for untrusted text to enter, because tool results, such as a fetched web page or a file listing, are read as context.

Without tools, a fooled model can only say something wrong. With tools, it can do something wrong, with whatever permissions those tools hold, and later steps can build on an earlier mistake. Loops can also run away, burning money or hammering an .

The Model Context Protocol () makes adding tools easy, which is why stage five is all about it.

Common trapreviewing the first prompt carefully and never looking at what enters on step seven.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking Prompt Engineering for Software Engineers

    Design Gurus · Beginner · Subscription

    How system prompts, context and structured output really work, the ground every LLM risk stands on

  • CourseFree
    Hugging Face Learn

    Hugging Face · Intermediate

    Free courses on how language models, embeddings and agents work, at an engineer's level

Practise

  • Run a small model locally as the heart of the practice app you will defend and test

  • Build your practice app's two tools as a tiny MCP server, so later stages have something real to secure

Keep handy

Also worth your time

Mark this stage as not done?