← Lessons

quiz vs the machine

Platinum1800

Machine Learning

Agent Guardrails and Sandboxing

Containing what an agent is allowed to do when it goes wrong.

5 min read · advanced · beat Platinum to climb

Agent Guardrails and Sandboxing

An agent that can run code or call APIs can also cause real damage. Guardrails constrain what it may do, and sandboxing limits the blast radius when it does something unexpected.

Layers of protection

  • Input filters catch malicious or out of scope requests before they reach tools.
  • Permission scoping gives each tool only the access it truly needs.
  • Output checks validate results before they are shown or acted upon.

Sandboxing execution

Code an agent writes should run in an isolated environment: a container or restricted runtime with no access to secrets, the host filesystem, or arbitrary network destinations. If the agent is tricked or simply confused, the damage stays inside the sandbox. This is essential defense against prompt injection, where hostile text in a tool result tries to hijack the agent.

Defense in depth

No single guardrail is sufficient because models can be persuaded and inputs can be crafted. Layering filters, least privilege tools, sandboxes, and human approval for risky actions means an attacker must defeat several independent controls. The goal is not a perfectly safe agent but a contained one whose worst case stays small.

Key idea

Guardrails restrict what an agent may do and sandboxing contains the damage, layered so no single failure is catastrophic.

Check yourself

Answer to earn rating on the learn ladder.

1. What is the purpose of sandboxing agent code execution?

2. What attack does sandboxing help defend against?

3. Why use defense in depth rather than one guardrail?