Part XVIII — LLM Agents, Tool Use, Planning & Multi-Agent Swarms · Chapter 8

Agent sandboxing & execution security

Hook

An agent that can only read files can be wrong about a lot, but the worst it can do is give you a bad answer. Give it the ability to execute arbitrary code and one wrong step can do real, unrecoverable damage. What's the smallest set of permissions that still lets it finish the job?

Intuition
weight 1
weight 2
weight 3
weight 5

Toggle permissions with no task in mind at all. Each one has its own cost — "execute arbitrary code" is weighted far higher than "read files" — and the bars simply add: granting more never makes the total blast radius smaller.

Formalize

Each permission ii carries a fixed risk weight wiw_i. A grant is a 0/1 indicator gig_i — off or on. The blast radius of a grant set is just the sum of the weights actually switched on, and a task succeeds only if every permission it genuinely requires is among them.

blast radius(g)=igiwi,succeeds(g)    Rg\text{blast radius}(\mathbf{g}) = \sum_i g_i \, w_i, \qquad \text{succeeds}(\mathbf{g}) \iff R \subseteq \mathbf{g}
  • gig_i — whether permission ii is granted (1) or not (0).
  • wiw_i — the fixed risk weight of permission ii (read: 1, write: 2, call an API: 3, execute code: 5).
  • RR — the set of permissions the task actually requires.
  • \subseteq — every permission in RR must also be in g\mathbf{g}; extra permissions in g\mathbf{g} beyond RR don't help.
  1. The task fixes R, not the agent's convenience

    "Fetch the latest price from an API and save it to a file" needs exactly write and api — nothing about the task touches the filesystem's existing contents or requires running arbitrary code.

  2. R = {write, api} sets a floor, not a target

    blast radius=wwrite+wapi=2+3=5\text{blast radius} = w_{\text{write}} + w_{\text{api}} = 2 + 3 = 5 is the minimum achievable while the task still succeeds — you cannot go lower without breaking it.

  3. Granting more only raises the sum

    Adding read on top costs +1+1 for zero gain: the task doesn't use it, so blast radius rises to 6 while capability stays exactly the same.

  4. Granting everything is the worst case, not the safe default

    1+2+3+5=111 + 2 + 3 + 5 = 11 — more than double the minimal 5 — for a task that only ever touches two of the four permissions.

Play

Task: fetch the latest price from an API and save it to a file.

weight 1
weight 2
weight 3
weight 5

With the task now stated explicitly, the readout tracks two things at once: whether it succeeds, and whether the current grant set is minimal. Start from every permission granted and remove them one at a time — the task keeps succeeding right up until you drop write or api.

Worked example

Starting from all four permissions granted, remove permissions one at a time and watch both numbers:

  1. All four granted

    blast radius =1+2+3+5=11= 1+2+3+5 = 11. Task succeeds — write and api are both present, plus two unused extras.

  2. Remove execute

    blast radius =1+2+3=6= 1+2+3 = 6. Task still succeeds — execute was never in RR, so removing it cost nothing in capability.

  3. Remove read

    blast radius =2+3=5= 2+3 = 5. Task still succeeds, and this is now the minimum — both remaining permissions are in RR and neither can be dropped.

  4. Remove api

    blast radius =2= 2. Task now fails — api was in RR, so removing it breaks the task even though the blast radius dropped further.

Checkpoint

Toggle permissions until the task still succeeds, with the blast radius as low as possible (target: 5).

weight 1
weight 2
weight 3
weight 5
Toggle permissions to try it
Summary
blast radius(g)=igiwi,succeeds(g)    Rg\text{blast radius}(\mathbf{g}) = \sum_i g_i \, w_i, \qquad \text{succeeds}(\mathbf{g}) \iff R \subseteq \mathbf{g}

The right grant set is exactly RR — no less, or the task breaks; no more, or the blast radius grows for nothing. In practice RR also isn't static: a well-sandboxed agent asks for permissions per step rather than up front for the whole session, so a prompt injection that hijacks step 2 still can't reach the permissions step 5 would have needed. The next chapter asks how you'd know, at scale, whether an agent with a given permission set actually gets real tasks done — not toy ones like this one.