Learn how to build a governance layer that enforces deterministic policies on AI agents, preventing dangerous actions before they execute.
Sign in to save downloads to your library and vote.
Preview
π‘οΈ AI Agent Governance - Policy-Based Sandboxing
Learn how to build a governance layer that enforces deterministic policies on AI agents, preventing dangerous actions before they execute.
Features
- Policy-Based Sandboxing: Define what your AI agent can and cannot do using declarative policies
- Action Interception: Catch and validate agent actions before execution
- Audit Logging: Full trail of agent actions for compliance and debugging
- File System Guards: Restrict read/write to specific directories
- Network Guards: Allowlist-only external API access
- Rate Limiting: Prevent runaway agents with configurable limits
How It Works
- Policy Definition: Define your security policies in YAML format
- Action Wrapping: Wrap your agent's tools with the governance layer
- Interception: Before any tool executes, the policy engine validates the action
- Decision: Actions are allowed, denied, or require human approval
- Audit: All decisions are logged for compliance and debugging
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Agent ββββββΆβ Governance ββββββΆβ Tool β
β (LLM) β β Layer β β Execution β
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β
ββββββββΌβββββββ
β Policy β
β Engine β
βββββββββββββββ
Requirements
- Python 3.8+
- OpenAI API key (or any LLM provider)
- Required Python packages (see
requirements.txt)
Installation
-
Clone this repository:
git clone https://github.com/Shubhamsaboo/awesome-llm-apps.git cd advanced_ai_agents/single_agent_apps/ai_agent_governance -
Install the required packages:
pip install -r requirements.txt
Usage
-
Set your API key:
export OPENAI_API_KEY=your-openai-api-key export OPENAI_MODEL=gpt-4 # optional, defaults to gpt-4 -
Run the governance demo:
python ai_agent_governance.py -
Try different actions and see how the policy engine handles them.
Example Policy Configuration
policies:
filesystem:
allowed_paths: ["/workspace", "/tmp"]
denied_paths: ["/etc", "/home", "~/.ssh"]
network:
allowed_domains: ["api.openai.com", "api.github.com"]
block_all_others: true
execution:
max_actions_per_minute: 60
require_approval_for: ["delete_file", "execute_shell"]
tools:
allowed: ["read_file", "write_file", "web_search"]
denied: ["execute_code", "send_email"]
Example Output
π‘οΈ AI Agent Governance Demo
============================
π Loading policy: workspace_sandbox.yaml
π€ Agent request: "Read the contents of /etc/passwd"
β DENIED: Path '/etc/passwd' is outside allowed directories
π€ Agent request: "Write analysis to /workspace/report.md"
β
ALLOWED: Action permitted by policy
π€ Agent request: "Make HTTP request to unknown-api.com"
β DENIED: Domain 'unknown-api.com' not in allowlist
π€ Agent request: "Delete /workspace/temp.txt"
βΈοΈ PENDING: Action requires human approval
[Y/n]:
Technical Details
Policy Engine
The policy engine evaluates actions against a set of rules:
class PolicyEngine:
def evaluate(self, action: Action) -> Decision:
# Check each policy rule
for rule in self.rules:
result = rule.evaluate(action)
if result.is_terminal:
return result
return Decision.ALLOW
Action Interception
Tools are wrapped with governance checks:
def governed_tool(func):
def wrapper(*args, **kwargs):
action = Action(name=func.__name__, args=args, kwargs=kwargs)
decision = policy_engine.evaluate(action)
if decision == Decision.DENY:
raise PolicyViolation(decision.reason)
elif decision == Decision.REQUIRE_APPROVAL:
if not get_human_approval(action):
raise PolicyViolation("Human denied the action")
# Log the action
audit_log.record(action, decision)
return func(*args, **kwargs)
return wrapper
Audit Logging
All actions are logged with full context:
{
"timestamp": "2024-01-15T10:30:00Z",
"action": "write_file",
"args": {"path": "/workspace/report.md"},
"decision": "ALLOW",
"policy_matched": "filesystem.allowed_paths",
"agent_id": "research-agent-001"
}
Key Concepts Learned
- Deterministic vs Probabilistic Safety: Why policy enforcement is more reliable than prompt engineering
- Defense in Depth: Multiple layers of validation for robust security
- Audit Trails: Importance of logging for compliance and debugging
- Principle of Least Privilege: Only grant the permissions agents actually need
Extending the Tutorial
- Add custom policy rules for your use case
- Implement human-in-the-loop approval workflows
- Connect to external policy management systems
- Add real-time monitoring and alerting
Related Projects
- LangChain - LLM application framework
- Guardrails AI - Input/output validation for LLMs
Ingestion metadata
- Source catalog
- awesome-llm-apps
- Repository
- Shubhamsaboo/awesome-llm-apps Β· main
- File path
- advanced_ai_agents/single_agent_apps/ai_agent_governance/README.md
- Last refreshed
- 10/24/2026, 3:00:14 AM (5h ago)
- Refresh schedule
- Daily Β· 03:00 UTC
- Dedupe status
- Unique Β· deduped by (source, url)