10 views
This guide focuses on AI agent policy as code for production systems, with practical trade-offs for reliability, security, and cost.
Prompt text saying “be careful with prod” is not a control. Put OPA/Cedar (or similar) in front of every risky tool — shell, apply, terraform, IAM — so policy is code reviewed and testable.
⚡ TL;DR: Tools call authorize(input) before side effects. Policies live in git. Unit-test allow/deny.
AI agent policy as code: production guidance
python
# policy/gate.py
import subprocess, json
def authorize(action: str, input_doc: dict) -> bool:
p = subprocess.run(
["opa", "eval", "-f", "values", "-d", "policy/", "data.agent.allow",
"-i", "/dev/stdin"],
input=json.dumps({"action": action, **input_doc}).encode(),
capture_output=True,
)
out = json.loads(p.stdout or "[]")
return bool(out and out[0] is True)
rego
# policy/shell.rego
package agent
default allow = false
allow {
input.action == "run_shell"
input.role == "implementer"
startswith(input.cwd, "/workspace")
not contains(input.cmd, "curl")
}
typescript
❌ Soft-prompt “don’t run curl” while still exposing unrestricted shell.
export async function runShell(role: string, cmd: string, cwd: string) {
if (!authorize("run_shell", { role, cmd, cwd })) throw new Error("policy_deny");
// proceed
}
Closing checklist
- [ ] Policy-as-code in git
- [ ] Authorize before side effects
- [ ] Unit tests for allow/deny tables
- [ ] Break-glass path with audit
- [ ] Same gate for apply/terraform/IAM tools
Series navigation
Day 68: Abuse and Cost Attacks · Day 70: Project: Secure Coding-Agent Sandbox on ECS Fargate Last updated September 11, 2026 Related: Policy-as-Code for AI: OPA Checks Before Every Shell Execution; Day 51: Multi-Agent Roles: Planner, Implementer, Critic; Day 53: Avoiding Agent Ping-Pong.Watch: 100 Days of AI on YouTube
Short videos from CheatCoders, one AI engineering topic per day.
Most viewed
- Python Decorators Explained: From Simple Wrappers to Production Patterns
- Claude Code vs Cursor vs GitHub Copilot: Choose by Workflow, and Set Up One Repo That Works With All Three
- AI Agent Frameworks in 2025: LangGraph vs CrewAI vs AutoGen vs Raw API
- Python String Methods: Every str Method With Real Production Examples
- Css Animation Performance: Performance-Optimized Motion for Modern UIs
Newly added
- AWS Systems Manager Parameter Store: Hierarchical Runtime Config for Coding Agents
- Amazon Cognito Identity Pools: Federate Coding-Agent Tool Callers Without Long-Lived Keys
- Amazon Athena for Coding Agents: Query Tool Audit Logs and Eval Traces on S3 Without a Warehouse
- AWS Batch for Coding Agents: Parallel Overnight PR Reviews and Long-Running Jobs Without Lambda Timeouts
- Amazon Bedrock Prompt Management: Version and A/B Test Coding-Agent System Prompts
Deep-dive PDF
Get the expanded guide for this post — extra diagrams-style checklists, failure modes, and a production walkthrough. Free when you subscribe to CheatCoders.
Already subscribed? or open the subscribe page.
Discover more from CheatCoders
Subscribe to get the latest posts sent to your email.
