Sandboxing and Least Privilege for Tools
What You'll Learn
You'll learn how to minimize damage from successful prompt injections by restricting what actions your LLM-powered tools can actually execute.
The Core Problem
Even with robust input filtering and defensive prompting, some prompt injection attacks will slip through. When your LLM has function-calling capabilities—accessing databases, sending emails, or triggering deployments—a successful injection could be catastrophic.
The principle: If an attacker can't cause much damage even when they succeed, your system remains resilient.
Sandboxing: Creating Safe Boundaries
Think of sandboxing like giving a child scissors with rounded tips instead of sharp kitchen shears. The tool still works for its intended purpose, but the worst-case outcome is limited.
For LLM tools, this means:
- Read-only by default: Functions should only retrieve data unless write access is absolutely necessary
- Isolated environments: Database connections with limited permissions, not admin credentials
- Resource limits: Cap file sizes, API call volumes, execution time
- Network restrictions: Prevent tools from accessing internal services or external URLs arbitrarily
Least Privilege: Grant Only What's Needed
Each function your LLM can call should have the minimum permissions required for its legitimate use case:
- A "check order status" function needs read access to order records—not the ability to cancel orders
- A "send notification" function should use a template system—not accept arbitrary email content
- A "retrieve document" function should access only public documents—not the entire filesystem
Implementation Strategy
Create wrapper functions that enforce boundaries before the actual operation executes. Log all tool invocations with full context. Use separate service accounts with scoped permissions for each category of function.
Key Takeaway: Defense in depth means even successful prompt injections hit walls of limited permissions—sandboxing and least privilege transform potential catastrophes into minor inconveniences.