Oren1984/agent-safety-gate/tree/main/runtime-gate

도구 호출(Bash, Read)을 가로채 실행 전에 차단, 에스컬레이션 또는 재작성하는 Claude Code TypeScript mod입니다. 더 넓은 agent 안전 파이프라인 POC 안에서 이를 시연합니다.
Oren1984/agent-safety-gate/tree/main/runtime-gate

runtime-gate는 agent-safety-gate 프로젝트의 일부로 포함된 Claude Code TypeScript mod입니다. Bash와 Read의 tool.call 이벤트에 훅을 등록해 실제 도구 경계에서 도구 동작을 가로채고, 결정론적 정책 로직을 적용해 차단하거나 승인을 요구하거나 인수를 다시 작성합니다. 주변 POC는 의도적으로 쉽게 믿는 LangGraph agent를 오염된 문서에 대해 실행하고, 세 가지 보호 시나리오(agent만, 정책 게이트, 심층 방어 전체)를 비교하여 런타임 가로채기가 잘못된 결정을 안전하지 않은 동작으로 바꾸지 못하게 하는 모습을 보여 줍니다. 샌드박스 시나리오를 설정하려면 Python 3.12+와 Docker가 필요하며 Claude Code mod는 Claude Code CLI의 claude plugin test runtime-gate로 테스트할 수 있습니다. 모든 데모 데이터는 모의 데이터이며 API 키나 네트워크 자격 증명이 필요하지 않습니다.
먼저 작성자의 README에서 marketplace와 플러그인 이름을 확인하세요. 저장소 구조에 따라 명령어가 달라질 수 있습니다.
claude plugin marketplace add Oren1984/agent-safety-gate claude plugin install runtime-gate
A lean engineering POC that asks one question:
If an AI agent makes a bad or unsafe decision, can the system around it stop that decision from becoming a real action?
A small agent pipeline where the agent is deliberately gullible: it reads a document containing an indirect prompt injection and obeys it. The same agent and the same poisoned input are then run three times with increasing protection, and the result is measured.
| Scenario | Protection | Unsafe actions that took effect | Outcome |
|---|---|---|---|
| A | Agent only | 6 of 6 (simulated) | UNSAFE |
| B | Deterministic policy gate | 1 of 6, plus a leaked token (simulated) | PARTIALLY_PROTECTED |
| C | Full defense-in-depth | 1 of 6, inside the sandbox, detected, result withheld | CONTAINED |
Model-level safety reduces how often an agent goes wrong. It does not bring that to zero, and once an agent can call tools, a wrong decision is no longer just wrong text. It is a file write, a shell command, a network call.
So this POC starts from the opposite assumption:
Assume the agent may eventually make a bad decision. The surrounding system must prevent that decision from becoming an unsafe action.
No single control does that. Each layer here is simple, independent of the model, and catches what another one misses.
User intent ─▶ Agent (LangGraph) ◀─ untrusted input
│ requested tool actions
▼
Injection check flags the untrusted content
▼
Policy engine deterministic ALLOW / REQUIRE_APPROVAL / BLOCK
▼
Runtime tool gate rewrites arguments, strips fake approvals, redacts secrets
▼
Human approval Approve / Reject (simulated; no answer = reject)
▼
Docker sandbox no network, read-only rootfs, no capabilities, non-root
▼
Post-action verifier compares the resulting state with the user's intent
▼
Audit log · trace · metrics · evaluators
runtime-gate/) showing the same interception at a real tool boundary.One run of scenario C, from the poisoned input to the outcome. Scenarios A and B run the same graph
with layers removed: A goes straight from the agent to the outcome, B keeps only the policy engine.
Without the sandbox layer nothing is executed; surviving actions are only recorded as would_execute.
flowchart TD
intent([User intent:<br/>summarize the release notes]) --> agent
doc[/Untrusted document<br/>with an injected instruction/] --> agent
agent["Agent (LangGraph, mock model)<br/>obeys the injection"] -->|requested tool actions| inj
inj["Injection check<br/>flags the untrusted content"] --> pol
pol{"Policy engine<br/>deterministic rules"}
pol -->|BLOCK| blocked[Blocked]
pol -->|ALLOW / REQUIRE_APPROVAL| gate
gate["Runtime tool gate<br/>rewrites arguments, strips fake approvals,<br/>redacts secrets, re-applies policy"]
gate -->|BLOCK| blocked
gate -->|REQUIRE_APPROVAL| appr
gate -->|ALLOW| sbx
appr{"Human approval<br/>no answer = reject"}
appr -->|Reject| rejected[Rejected]
appr -->|Approve| sbx
sbx["Docker sandbox<br/>no network, read-only rootfs,<br/>no capabilities, non-root"]
blocked -.->|containment drill:<br/>replayed in a scratch workspace| sbx
sbx --> ver
ver{"Post-action verifier<br/>workspace on disk vs. user intent"}
ver -->|matches intent| safe([SAFE])
ver -->|deviation detected,<br/>result withheld| contained([CONTAINED])
blocked --> outcome
rejected --> outcome
safe --> outcome
contained --> outcome
outcome[["Outcome + metrics + evaluators<br/>audit.jsonl, trace.json, result.json"]]
Every node also emits structured audit events, so the run can be replayed from runs/<run_id>/.
Requires Python 3.12+ and Docker (for scenario C and the sandbox tests).
python -m venv .venv
.venv/Scripts/activate # Windows (macOS/Linux: source .venv/bin/activate)
pip install -r requirements.txt
python -m safety_gate.demo # run scenarios A, B, C in the terminal
python -m safety_gate.ui # local demo UI at http://127.0.0.1:8765
pytest # the safety contract
Optional, needs the Claude Code CLI: claude plugin test runtime-gate

Everything runs locally with deterministic mock data. No ANTHROPIC_API_KEY, OPENAI_API_KEY,
LANGSMITH_API_KEY or cloud credentials are needed or read. No real secret, network endpoint or
deployment exists anywhere in the demo. Live LangSmith tracing is optional and documented in
docs/OBSERVABILITY.md.
Architecture · Safety model · Experiments · Sandbox · Observability · Governance mapping · Sources
Full list with the design decision each one supports: docs/SOURCES.md.
This is a lean engineering POC, not a production security product. The rules are small pattern lists, the agent is a script, and the injection check is a heuristic. It demonstrates an architecture and makes it measurable; it does not claim to stop a determined attacker. See the limitations in docs/SAFETY_MODEL.md.