Environment Boundaries and Constraints › Practical Considerations
AI Agent HandbookAll chapters Environment Boundaries and Constraints › Practical ConsiderationsOne section · Sections in this chapter7 / 11 ↓
When implementing boundaries for your agent, keep these principles in mind:
Start restrictive, then relax: It's easier to grant new permissions than to revoke them. Begin with tight constraints and loosen them as you gain confidence in your agent's behavior.
Make boundaries visible: Users should know what your agent can and cannot do. Don't hide limitations. Instead, communicate them clearly: "I can read your calendar but I'll ask before creating events."
Log boundary violations: When your agent tries to do something it can't, log it. These logs reveal where your constraints might be too tight or where your agent's logic needs improvement.
Test boundaries explicitly: Write tests that verify your agent respects its boundaries. Try to make it access forbidden resources or exceed rate limits. Your boundary system should catch these attempts.
Consider context: Some boundaries might change based on context. Your agent might have more permissions during work hours than at night, or more access when you're actively interacting with it than when it's running autonomously.
Here's a simple context-aware boundary system:
## Example (Claude Sonnet 4.5)
## Using Claude Sonnet 4.5 for context-aware permission logic
from datetime import datetime
class ContextAwareBoundaries:
def __init__(self, base_permissions):
self.base_permissions = base_permissions
def get_permissions(self, context):
"""Get permissions based on current context"""
permissions = self.base_permissions.copy()
# More permissions during work hours
if self.is_work_hours():
permissions["email"].append("send")
permissions["calendar"].append("delete")
# More permissions when user is actively present
if context.get("user_present"):
permissions["files"] = ["read", "write"]
return permissions
def is_work_hours(self):
"""Check if it's currently work hours"""
now = datetime.now()
return 9 <= now.hour < 17 and now.weekday() < 5
## Base permissions (always available)
base_perms = {
"calendar": ["read"],
"email": ["read", "draft"],
"contacts": ["read"],
}
boundaries = ContextAwareBoundaries(base_perms)
## Get permissions for current context
context = {"user_present": True}
current_permissions = boundaries.get_permissions(context)
print("Current permissions:", current_permissions)Current permissions: {'calendar': ['read'], 'email': ['read', 'draft'], 'contacts': ['read'], 'files': ['read', 'write']}Context-aware boundaries make your agent more flexible while maintaining safety. The agent has more freedom when it makes sense (during work hours, when you're present) and less when risks are higher.