Module 9 · Lesson 5 · 16 min read
Permissions and isolation
Permissions and Sandboxing
Introduction
If we cannot guarantee that the model will not be tricked or make a mistake, the practical question becomes: what is the maximum damage that could happen? This is where permissions and isolation come in. In this lesson we design a permission policy for the agent's tools, build an isolated file-reading tool that prevents escaping its folder, and decide when to ask for human approval.
Learning objectives
- Apply the principle of least privilege to the agent's tools and credentials
- Classify tools by danger and reversibility
- Build an isolated file tool that prevents path traversal
- Set operational limits for the agent: steps, time and cost
The principle of least privilege
The principle of least privilege is old in information security: give each component only what it needs for its task, for the shortest possible time. In the world of agents this means three levels:
- Tool level: do not give the agent a tool its task does not need. A question-answering agent does not need a delete tool.
- Parameter level: even an allowed tool can be restricted, such as reading from only one table, or sending email only to the university domain.
- Credential level: the agent works with a limited-privilege service account, not an administrator account. If the model is tricked, it cannot exceed what the account allows.
Secrets do not enter the context
A related rule: do not put API keys or passwords inside the model's instructions or in tool results. The tool itself reads the key from an environment variable or a secrets vault at execution time, and the model sees only the tool's name and parameters. This way prompt injection cannot ask the model to "print the key", because the model does not know it in the first place. It also makes it easy to rotate the key without changing the agent's instructions.
Classifying tools by danger
Classify each tool according to two questions: does it change something in the world? And can the change be undone?
| Category | Examples | Proposed policy |
|---|---|---|
| Read only | knowledge_search, file_reader | Allowed automatically, with logging |
| Reversible write | Creating a draft, adding a note | Allowed with limits and logging |
| Irreversible write | Sending email, paying, deleting | Human approval for every call |
When asking for approval, show the user the real action and its parameters as they will be executed, not the model's description of it. There is a big difference between "I will send the summary to your colleague" and showing the actual address and message text.
Isolation (Sandboxing)
Isolation means running what the agent executes in a limited environment that cannot reach the rest of the system. Examples:
- Running the code the agent writes in a temporary container or virtual machine with no network access except to specific domains.
- Restricting the file tool to a single working folder.
- Resource limits: a maximum execution time and limited memory.
Practical example: an isolated file-reading tool
A common problem: a file_reader tool takes a file name from the model. If the model (or an attacker through injection) passes a path such as ../../etc/passwd, the tool may read files outside the intended folder. The following code solves this in standard Python:
from pathlib import Path
WORKSPACE = Path("/tmp/agent_workspace").resolve()
WORKSPACE.mkdir(parents=True, exist_ok=True)
(WORKSPACE / "notes.txt").write_text("Notes from the third lecture", encoding="utf-8")
def safe_read(relative_name, max_bytes=10_000):
target = (WORKSPACE / relative_name).resolve()
# We check that the final path is still inside the working folder
if not target.is_relative_to(WORKSPACE):
return {"isError": True, "message": "The path is outside the working folder"}
if not target.is_file():
return {"isError": True, "message": "The file does not exist"}
return {"isError": False, "text": target.read_text(encoding="utf-8")[:max_bytes]}
print(safe_read("notes.txt"))
print(safe_read("../../etc/passwd"))Notice that the tool returns a structured error the agent understands instead of throwing an exception that stops the program, and that it limits the size of the output so it does not flood the model's context. The is_relative_to function has been available since Python 3.9.
Operational limits
Even a safe agent may enter an endless loop or consume a large budget. Set explicit limits:
- A maximum number of steps or turns per run. Frameworks such as the OpenAI Agents SDK provide a parameter for this (
max_turns) and raise aMaxTurnsExceededexception when it is exceeded (according to the official documentation, reviewed 18 November 2026). - A time limit for each tool and for each run.
- A limit on the cost or the number of tokens per user per day.
- A limited call rate for external tools.
And when any limit is reached, the agent stops with an honest answer such as "I could not complete the task within the allowed limits", and the event is logged for review.
Summary
Least privilege is applied at three levels: tools, parameters and credentials. Classifying tools by change and reversibility determines when we allow automatically and when we ask for human approval that shows the real action. Isolation confines the agent's execution to a limited environment; one example is preventing path traversal in the file tool. And operational limits on steps, time and cost prevent endless loops and excessive consumption.
Terms
| Term | English | Definition |
|---|---|---|
| The principle of least privilege | Principle of Least Privilege | Giving each component the minimum permissions needed for its task |
| Sandbox | Sandbox | A limited execution environment that cannot reach the rest of the system |
| Path traversal | Path Traversal | Using paths such as ../ to reach files outside the allowed folder |
| Service account | Service Account | An account dedicated to the program with specific permissions instead of a person's account |
| Rate limit | Rate Limit | A maximum number of calls within a period of time |
Review questions
- Apply least privilege at the three levels to an agent that answers students' questions from the college's regulations.
- Why must the approval screen show the real action's parameters and not the model's description of it?
- How does checking after resolve prevent a path traversal attack?
- What should the agent do when it reaches the step limit?
References
- OWASP Top 10 for LLM Applications owasp.org Reviewed on 2026-11-18
- Running agents (OpenAI Agents SDK) openai.github.io Reviewed on 2026-11-18
