Commit 8bc02fb
feat(policy): SRS-backed per-agent guardrails (Cedar + OPA)
Adds an engine-agnostic policy abstraction at the ComputerAgent layer.
A PolicyDecider gates every tool call before the engine dispatches it;
denies short-circuit with behavior:"deny" and never reach the tool.
Why ComputerAgent-level, not per-engine: policy is the fourth orthogonal
axis alongside engine/substrate/memory. Configure once at the harness;
all engines (claude-agent-sdk, gitagent) inherit enforcement via the
existing onPermissionRequest contract — engines don't need to know about
Cedar/OPA/SRS.
How it works:
- protocol: PolicyDecider, ToolCallContext, PolicyDecision, PolicyConfig
types; CreateSessionBody gains an optional policy field.
- harness-server: SrsPolicyDecider fetches the RAI policy from SRS once,
caches cedar_guardrail + opa_guardrail, calls
/v1/guardrails/evaluate-tool-call per turn. run-session wraps
onPermissionRequest so a bound decider gates ahead of any client
mediation.
- engine-claude-agent-sdk: PreToolUse hook added so the gate fires even
in bypassPermissions mode (where canUseTool is skipped). gitagent
already routed preToolUse → onPermissionRequest.
- sdk: ComputerAgent constructor accepts policy; forwarded into
POST /v1/sessions.
- AgentOS server: /agentos/api/policies/* proxy SRS (LYZR_API_KEY never
reaches the browser); /agentos/api/opa-policies/* proxies SRS's
standalone Rego policies. agent_policy_bindings collection in Mongo
holds the per-agent policy_id binding. chat-sandbox reads the binding
and forwards a policy spec to /sandboxes.
- AgentOS UI: Policies page (list / create / edit / delete Cedar +
OPA), Rego policy modal, per-agent policy tab with attach/detach.
Mirrors the shape of Lyzr's SRS guardrail-evaluate endpoint:
ToolCallContext → {allowed, deniedBy, reason}. New policy engines drop
in by implementing PolicyDecider and branching on PolicyConfig.kind in
create-session.
Verified end-to-end: claude-code denies Bash with destructive shell
patterns (OPA), Write/Edit (Cedar), WebFetch outside an allowlist (OPA);
safe Bash and allowlisted WebFetch pass through.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent d2df145 commit 8bc02fb
19 files changed
Lines changed: 1272 additions & 16 deletions
File tree
- agentos/src
- components
- examples
- packages
- engine-claude-agent-sdk/src
- harness-server/src
- services
- protocol/src
- sdk/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | | - | |
9 | | - | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
| |||
91 | 93 | | |
92 | 94 | | |
93 | 95 | | |
94 | | - | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
100 | 102 | | |
101 | 103 | | |
102 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
| |||
145 | 155 | | |
146 | 156 | | |
147 | 157 | | |
148 | | - | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
149 | 161 | | |
150 | 162 | | |
151 | 163 | | |
| |||
161 | 173 | | |
162 | 174 | | |
163 | 175 | | |
164 | | - | |
| 176 | + | |
165 | 177 | | |
166 | 178 | | |
167 | 179 | | |
| |||
185 | 197 | | |
186 | 198 | | |
187 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
188 | 208 | | |
189 | 209 | | |
190 | 210 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
51 | 104 | | |
52 | 105 | | |
53 | 106 | | |
| |||
122 | 175 | | |
123 | 176 | | |
124 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
125 | 200 | | |
0 commit comments