guardledger 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- guardledger-0.1.0.dist-info/METADATA +180 -0
- guardledger-0.1.0.dist-info/RECORD +26 -0
- guardledger-0.1.0.dist-info/WHEEL +4 -0
- guardledger-0.1.0.dist-info/entry_points.txt +2 -0
- guardledger-0.1.0.dist-info/licenses/LICENSE +173 -0
- sentinel/__init__.py +53 -0
- sentinel/api.py +126 -0
- sentinel/approvals.py +122 -0
- sentinel/audit.py +171 -0
- sentinel/cli.py +166 -0
- sentinel/compliance.py +77 -0
- sentinel/config.py +46 -0
- sentinel/dashboard/index.html +197 -0
- sentinel/db.py +19 -0
- sentinel/detector.py +97 -0
- sentinel/frameworks.py +239 -0
- sentinel/killswitch.py +58 -0
- sentinel/mcp_proxy.py +61 -0
- sentinel/mcp_server.py +79 -0
- sentinel/models.py +88 -0
- sentinel/otel.py +80 -0
- sentinel/policy.py +128 -0
- sentinel/py.typed +0 -0
- sentinel/ratelimit.py +46 -0
- sentinel/redaction.py +46 -0
- sentinel/sentinel.py +191 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: guardledger
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Sentinel — compliance-grade flight recorder + kill switch for AI agents
|
|
5
|
+
Author: Itamar Meirovich
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: agent-governance,ai-agents,ai-security,audit,compliance,eu-ai-act,guardrails,mcp
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Requires-Dist: fastapi>=0.110
|
|
17
|
+
Requires-Dist: pyyaml>=6.0
|
|
18
|
+
Requires-Dist: uvicorn>=0.29
|
|
19
|
+
Provides-Extra: dev
|
|
20
|
+
Requires-Dist: build>=1.0; extra == 'dev'
|
|
21
|
+
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
22
|
+
Requires-Dist: mcp>=1.0; extra == 'dev'
|
|
23
|
+
Requires-Dist: opentelemetry-sdk>=1.20; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
26
|
+
Provides-Extra: mcp
|
|
27
|
+
Requires-Dist: mcp>=1.0; extra == 'mcp'
|
|
28
|
+
Provides-Extra: otel
|
|
29
|
+
Requires-Dist: opentelemetry-sdk>=1.20; extra == 'otel'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# Sentinel
|
|
33
|
+
|
|
34
|
+
[](https://github.com/itamarmeirovichai-source/sentinel/actions/workflows/ci.yml)
|
|
35
|
+
[](LICENSE)
|
|
36
|
+
[](pyproject.toml)
|
|
37
|
+
|
|
38
|
+
**The compliance-grade flight recorder + kill switch for AI agents.**
|
|
39
|
+
|
|
40
|
+
Sentinel sits between **any** AI agent (any framework) and its tools. Every action is
|
|
41
|
+
checked against your policy *before* it runs, recorded into a tamper-evident
|
|
42
|
+
audit trail you can replay and export as compliance evidence, and you can stop
|
|
43
|
+
the agent instantly. The point is provability: knowing — and being able to
|
|
44
|
+
prove — exactly what your agent did.
|
|
45
|
+
|
|
46
|
+
> Status: **MVP / alpha (v0.1).** This is the narrow wedge of a larger vision (see
|
|
47
|
+
> [RESEARCH.md](RESEARCH.md) and [ROADMAP.md](ROADMAP.md)). It is **not** another
|
|
48
|
+
> prompt-injection filter — it leads with deterministic enforcement + provable audit.
|
|
49
|
+
>
|
|
50
|
+
> ⚠️ **Disclaimer.** Experimental; APIs may change; provided "as is", no warranty
|
|
51
|
+
> (Apache-2.0). Compliance mappings (EU AI Act Art. 12, OWASP) are **indicative
|
|
52
|
+
> engineering aids — not legal advice or a certification**. You remain responsible for
|
|
53
|
+
> your own compliance and for reviewing Sentinel before relying on it in high-stakes systems.
|
|
54
|
+
|
|
55
|
+
## Why
|
|
56
|
+
|
|
57
|
+
Teams can't get sign-off to let agents touch high-stakes systems (trading,
|
|
58
|
+
billing, prod DBs) because there's no audit-grade record of what the agent did,
|
|
59
|
+
no enforcement of what it's allowed to do, and no instant stop. Regulation now
|
|
60
|
+
forces the issue: **EU AI Act Article 12** mandates automatic event logging for
|
|
61
|
+
high-risk systems (enforcement from **2026-08-02**). Sentinel is the layer that
|
|
62
|
+
produces that evidence. Full market/competitive analysis: [RESEARCH.md](RESEARCH.md).
|
|
63
|
+
|
|
64
|
+
## Core guarantees
|
|
65
|
+
|
|
66
|
+
- **Default-deny** — an action with no matching allow rule is blocked.
|
|
67
|
+
- **Fail-closed** — if the decision core itself errors, the action is blocked, not run.
|
|
68
|
+
- **Tamper-evident** — the audit log is hash-chained; any edit/reorder/delete is detectable via `verify`.
|
|
69
|
+
|
|
70
|
+
## Architecture (one glance)
|
|
71
|
+
|
|
72
|
+
```
|
|
73
|
+
agent ─tool_call─► Interceptor ─► KillSwitch? ─► Detector(flags) ─► Policy(default-deny)
|
|
74
|
+
│
|
|
75
|
+
audit (hash-chained, redacted) ◄── execute / block
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Interception is an SDK wrapper today, behind an `Interceptor` interface so an
|
|
79
|
+
MCP-proxy adapter slots in later without touching the policy/audit/kill core.
|
|
80
|
+
Details + threat model: [ARCHITECTURE.md](ARCHITECTURE.md).
|
|
81
|
+
|
|
82
|
+
## Quickstart
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
python3 -m venv .venv && source .venv/bin/activate
|
|
86
|
+
pip install -e ".[dev]"
|
|
87
|
+
cp .env.example .env
|
|
88
|
+
|
|
89
|
+
# run the tests (security-critical core is tested first)
|
|
90
|
+
pytest
|
|
91
|
+
|
|
92
|
+
# run the end-to-end demo (a generic agent; see DEMO.md)
|
|
93
|
+
python examples/generic_agent.py # or: sentinel demo
|
|
94
|
+
|
|
95
|
+
# launch the control API + dashboard
|
|
96
|
+
sentinel serve # then open http://127.0.0.1:8787
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
> Shortcut: `make install && make test && make demo`.
|
|
100
|
+
> On PyPI the package is **`guardledger`** (the `sentinel` handle is taken); the import
|
|
101
|
+
> name and CLI stay `sentinel` — `pip install guardledger` → `import sentinel`.
|
|
102
|
+
|
|
103
|
+
## Usage sketch
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
from sentinel import Sentinel
|
|
107
|
+
|
|
108
|
+
sentinel = Sentinel.from_files(policy="policies/starter.yaml", db="data/sentinel.db")
|
|
109
|
+
|
|
110
|
+
@sentinel.guard # every call is checked, logged, killable
|
|
111
|
+
def send_email(to: str, subject: str, body: str): ...
|
|
112
|
+
|
|
113
|
+
# …or guard a whole toolset at once:
|
|
114
|
+
tools = sentinel.wrap_all({"send_email": send_email, "search_web": search_web})
|
|
115
|
+
|
|
116
|
+
# over-policy / killed / suspicious calls raise BlockedError and are recorded;
|
|
117
|
+
# allowed calls run normally and are recorded with their outcome.
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Works with any agent, any framework
|
|
121
|
+
|
|
122
|
+
Plain Python functions, LangChain, OpenAI Agents SDK, CrewAI, LlamaIndex, or MCP — guard
|
|
123
|
+
your tools with `@sentinel.guard` / `sentinel.wrap_all(...)`, or use the MCP proxy/server.
|
|
124
|
+
See [INTEGRATIONS.md](INTEGRATIONS.md). The default demo (`sentinel demo`) is a generic
|
|
125
|
+
agent; [`examples/trading_agent.py`](examples/trading_agent.py) is a vertical example.
|
|
126
|
+
|
|
127
|
+
## Two interceptors, one core
|
|
128
|
+
|
|
129
|
+
The SDK wrapper is the default. For agents that reach tools over **MCP**, the same
|
|
130
|
+
enforcement (`Sentinel.enforce`) runs behind a proxy — nothing the agent calls can
|
|
131
|
+
bypass it:
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from sentinel import MCPProxy, SentinelMCPServer
|
|
135
|
+
|
|
136
|
+
proxy = MCPProxy(sentinel, upstream=my_mcp_session) # guard calls to upstream MCP servers
|
|
137
|
+
server = SentinelMCPServer(sentinel) # OR expose your own tools over MCP
|
|
138
|
+
server.add_tool("get_quote", get_quote) # with enforcement built in
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Install the optional transports with `pip install "guardledger[mcp,otel]"`.
|
|
142
|
+
|
|
143
|
+
## Operating it
|
|
144
|
+
|
|
145
|
+
- **Monitor mode** — `SENTINEL_MODE=monitor` (or `Sentinel(mode="monitor")`) logs the
|
|
146
|
+
would-be verdict and **never blocks** — the kill switch still works. Deploy in front of
|
|
147
|
+
a live agent, watch, build trust, then flip to enforce. (Try `SENTINEL_MODE=monitor sentinel demo`.)
|
|
148
|
+
- **Dashboard auth** — set `SENTINEL_API_TOKEN` (or let `sentinel serve` generate one);
|
|
149
|
+
mutating endpoints (kill / policy / approve) then require `Authorization: Bearer …`.
|
|
150
|
+
- **Human-in-the-loop** — a `require_approval` call is parked; approve it from the
|
|
151
|
+
dashboard or `sentinel approve <id>`, and the next identical call runs exactly once.
|
|
152
|
+
- **Interop** — `sentinel export --format otel` emits OpenTelemetry GenAI spans
|
|
153
|
+
(`gen_ai.*`) for Langfuse / Datadog / any OTel backend.
|
|
154
|
+
- **Compliance** — `sentinel compliance --all` maps Sentinel to EU AI Act, GDPR, NIST AI
|
|
155
|
+
RMF, ISO 42001, Colorado AI Act, and SEC/FINRA with honest full/partial/none coverage
|
|
156
|
+
([COMPLIANCE.md](COMPLIANCE.md)); `sentinel export --format art12` produces an EU AI Act
|
|
157
|
+
Article 12 record-keeping report.
|
|
158
|
+
- **Housekeeping** — `sentinel gc` purges stale approvals / rate-limit state (never the audit log).
|
|
159
|
+
- **Overhead** — ~0.4 ms per guarded call on a dev laptop (policy + detector + two durable
|
|
160
|
+
audit writes), well under the 20 ms target. Reproduce: `python examples/benchmark.py`.
|
|
161
|
+
|
|
162
|
+
## Documents
|
|
163
|
+
|
|
164
|
+
| File | What |
|
|
165
|
+
|---|---|
|
|
166
|
+
| [RESEARCH.md](RESEARCH.md) | Market & competitive research, wedge recommendation |
|
|
167
|
+
| [PRD.md](PRD.md) | Product requirements for this MVP |
|
|
168
|
+
| [ARCHITECTURE.md](ARCHITECTURE.md) | Components, data flow, threat model |
|
|
169
|
+
| [DECISIONS.md](DECISIONS.md) | Decision log |
|
|
170
|
+
| [INTEGRATIONS.md](INTEGRATIONS.md) | Add Sentinel to any framework (LangChain, OpenAI, CrewAI, MCP, …) |
|
|
171
|
+
| [LAUNCH.md](LAUNCH.md) | The honest go-to-market plan + ready-to-post launch assets (`launch/`, `site/`) |
|
|
172
|
+
| [DEMO.md](DEMO.md) | How to run the end-to-end demo |
|
|
173
|
+
| [ROADMAP.md](ROADMAP.md) | What's next, and the known-limitation → feature map |
|
|
174
|
+
| [SECURITY.md](SECURITY.md) | Design posture, self-check, known limitations |
|
|
175
|
+
| [COMPLIANCE.md](COMPLIANCE.md) | Mapping to AI/data law (EU AI Act, GDPR, NIST, ISO 42001, Colorado, SEC/FINRA) |
|
|
176
|
+
| [CHANGELOG.md](CHANGELOG.md) | Release notes |
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
Apache-2.0.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
sentinel/__init__.py,sha256=6s0UZzE1Ly3TDZrHvlv43zbyvVU1SlmPtc_GajxR00M,1224
|
|
2
|
+
sentinel/api.py,sha256=zkp9Z5jveKJXYpwbCivBKbmP_9JQXBzWsqCuXb1159k,5038
|
|
3
|
+
sentinel/approvals.py,sha256=fNW3cKTLnsDTIMzMMTbKUmtoS1kuaW3_9Nd6CXQPyCE,4910
|
|
4
|
+
sentinel/audit.py,sha256=zjq81Bh-u6fYmcnjbgAUXDKJQybF4hDKlhMOdJ-smi8,7639
|
|
5
|
+
sentinel/cli.py,sha256=ynGA1WgG1z9feQ7Q36utfxoPhasn_KXdLd4htVlnJ_o,6813
|
|
6
|
+
sentinel/compliance.py,sha256=YlW7uGUuUEaVlthMMclXpVvdynvZ5TgpP_lU_KW2Xmc,3233
|
|
7
|
+
sentinel/config.py,sha256=uM_mD0C-dcJAxM-eN7aVk7DnJcQJSBhIt3oHQFW2E38,1852
|
|
8
|
+
sentinel/db.py,sha256=SuS_QezsUtDOL0boNfmpVCbQnF2JgUvsA_JJGra-9uM,750
|
|
9
|
+
sentinel/detector.py,sha256=Wq01ca6764uI2viK75MC-orBH8RkAXQEFd0WPZEZJSM,4536
|
|
10
|
+
sentinel/frameworks.py,sha256=oa5oNPifqcUH472pJNS05WpQtXT0O5UFMnbKP-IErRU,13258
|
|
11
|
+
sentinel/killswitch.py,sha256=7eRRuScTc2UZTSlTr8HCaUYhInuT_qdYNvh4qpHGgEs,2078
|
|
12
|
+
sentinel/mcp_proxy.py,sha256=UjUYthzbJf4IwNkGKYEDb8T2GMY3Zi3fyedNicAm-q0,2869
|
|
13
|
+
sentinel/mcp_server.py,sha256=YFotaJQE797-I1mNcafFJSS2PeDQ094ZSg2p1HSwLW8,3145
|
|
14
|
+
sentinel/models.py,sha256=Ct-S7QYSgmxGXSWwk3s0yj6tE5qu5LaxYicvrY3CFi8,2316
|
|
15
|
+
sentinel/otel.py,sha256=FBoAWJpkvmWk5Dc0ob-daBXJErP-7rSth5jHFgiVG8Q,3051
|
|
16
|
+
sentinel/policy.py,sha256=uSya438cc40M6UGpbL94UkjHcCvLU3WBjAA4M5f7fas,4861
|
|
17
|
+
sentinel/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
18
|
+
sentinel/ratelimit.py,sha256=kMerTgWdjkLsmntLcp4W8ttIG66yGu2i6lYBisAlaeQ,1964
|
|
19
|
+
sentinel/redaction.py,sha256=JyW00eXEQR1FBg3S2_I7-IpteJ2QGRmNXr0sm8UeosU,1769
|
|
20
|
+
sentinel/sentinel.py,sha256=BwcqpEtopbNp6X8ZDIZTuJMmgSDHVE9tWiWflNKD2MI,8507
|
|
21
|
+
sentinel/dashboard/index.html,sha256=-Fhzs6ou0PX4PkHErI5cbJQ3e3LL0-24Zc2s-KvvTPs,9008
|
|
22
|
+
guardledger-0.1.0.dist-info/METADATA,sha256=yx_3EXIIpl9HeEzXmxZw98H6eGZCeHHp587ytv0Jvo0,8399
|
|
23
|
+
guardledger-0.1.0.dist-info/WHEEL,sha256=mffPy8wBnZQn2VnJUU5jE99KsxaSfiyMHV9Yt0aLVxs,87
|
|
24
|
+
guardledger-0.1.0.dist-info/entry_points.txt,sha256=ocLIRMq9Ouq9WNyGxm5wf_4S_Lg_L_FA3jBcXo9o2kw,47
|
|
25
|
+
guardledger-0.1.0.dist-info/licenses/LICENSE,sha256=bumBeFxE99gYKvJrs76oaJk2nsk4qLh0TLAoKYU46Ls,9446
|
|
26
|
+
guardledger-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work; and
|
|
103
|
+
|
|
104
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
105
|
+
distribution, then any Derivative Works that You distribute must
|
|
106
|
+
include a readable copy of the attribution notices contained
|
|
107
|
+
within such NOTICE file.
|
|
108
|
+
|
|
109
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
110
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
111
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
112
|
+
this License, without any additional terms or conditions.
|
|
113
|
+
|
|
114
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
115
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
116
|
+
except as required for reasonable and customary use in describing the
|
|
117
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
118
|
+
|
|
119
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed
|
|
120
|
+
to in writing, Licensor provides the Work (and each Contributor
|
|
121
|
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES
|
|
122
|
+
OR CONDITIONS OF ANY KIND, either express or implied, including,
|
|
123
|
+
without limitation, any warranties or conditions of TITLE,
|
|
124
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
|
|
125
|
+
PURPOSE. You are solely responsible for determining the
|
|
126
|
+
appropriateness of using or redistributing the Work.
|
|
127
|
+
|
|
128
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
129
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
130
|
+
unless required by applicable law (such as deliberate and grossly
|
|
131
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
132
|
+
liable to You for damages, including any direct, indirect, special,
|
|
133
|
+
incidental, or consequential damages of any character arising as a
|
|
134
|
+
result of this License or out of the use or inability to use the
|
|
135
|
+
Work.
|
|
136
|
+
|
|
137
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
138
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
139
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
140
|
+
or other liability obligations and/or rights consistent with this
|
|
141
|
+
License. However, in accepting such obligations, You may act only
|
|
142
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
143
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
144
|
+
defend, and hold each Contributor harmless for any liability
|
|
145
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
146
|
+
of your accepting any such warranty or additional liability.
|
|
147
|
+
|
|
148
|
+
END OF TERMS AND CONDITIONS
|
|
149
|
+
|
|
150
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
151
|
+
|
|
152
|
+
To apply the Apache License to your work, attach the following
|
|
153
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
154
|
+
replaced with your own identifying information. (Don't include
|
|
155
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
156
|
+
comment syntax for the file format. We also recommend that a
|
|
157
|
+
file or class name and description of purpose be included on the
|
|
158
|
+
same "printed page" as the copyright notice for easier
|
|
159
|
+
identification within third-party archives.
|
|
160
|
+
|
|
161
|
+
Copyright 2026 Itamar Meirovich
|
|
162
|
+
|
|
163
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
164
|
+
you may not use this file except in compliance with the License.
|
|
165
|
+
You may obtain a copy of the License at
|
|
166
|
+
|
|
167
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
168
|
+
|
|
169
|
+
Unless required by applicable law or agreed to in writing, software
|
|
170
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
171
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
172
|
+
See the License for the specific language governing permissions and
|
|
173
|
+
limitations under the License.
|
sentinel/__init__.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Sentinel — compliance-grade flight recorder + kill switch for AI agents.
|
|
2
|
+
|
|
3
|
+
Typical use:
|
|
4
|
+
|
|
5
|
+
from sentinel import Sentinel
|
|
6
|
+
s = Sentinel.from_files(policy="policies/example.yaml", db="data/sentinel.db")
|
|
7
|
+
|
|
8
|
+
@s.guard
|
|
9
|
+
def place_order(symbol: str, amount: float): ...
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from sentinel.approvals import Approvals
|
|
13
|
+
from sentinel.audit import AuditLog, VerifyResult
|
|
14
|
+
from sentinel.detector import Detector
|
|
15
|
+
from sentinel.killswitch import KillSwitch
|
|
16
|
+
from sentinel.mcp_proxy import AsyncMCPProxy, MCPProxy
|
|
17
|
+
from sentinel.mcp_server import SentinelMCPServer
|
|
18
|
+
from sentinel.models import (
|
|
19
|
+
AuditRecord,
|
|
20
|
+
CheckResult,
|
|
21
|
+
Decision,
|
|
22
|
+
Flag,
|
|
23
|
+
Status,
|
|
24
|
+
ToolCall,
|
|
25
|
+
)
|
|
26
|
+
from sentinel.policy import Policy, PolicyResult
|
|
27
|
+
from sentinel.ratelimit import SqliteRateLimiter
|
|
28
|
+
from sentinel.sentinel import BlockedError, Sentinel
|
|
29
|
+
|
|
30
|
+
__version__ = "0.1.0"
|
|
31
|
+
|
|
32
|
+
__all__ = [
|
|
33
|
+
"Sentinel",
|
|
34
|
+
"BlockedError",
|
|
35
|
+
"MCPProxy",
|
|
36
|
+
"AsyncMCPProxy",
|
|
37
|
+
"SentinelMCPServer",
|
|
38
|
+
"Policy",
|
|
39
|
+
"PolicyResult",
|
|
40
|
+
"AuditLog",
|
|
41
|
+
"VerifyResult",
|
|
42
|
+
"KillSwitch",
|
|
43
|
+
"Detector",
|
|
44
|
+
"Approvals",
|
|
45
|
+
"SqliteRateLimiter",
|
|
46
|
+
"ToolCall",
|
|
47
|
+
"Decision",
|
|
48
|
+
"Status",
|
|
49
|
+
"Flag",
|
|
50
|
+
"CheckResult",
|
|
51
|
+
"AuditRecord",
|
|
52
|
+
"__version__",
|
|
53
|
+
]
|
sentinel/api.py
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"""Minimal control plane: a FastAPI app exposing the audit trail, integrity check,
|
|
2
|
+
policy, approvals, and the kill switch — plus a single-page dashboard.
|
|
3
|
+
|
|
4
|
+
The API and any running agent share state through the SQLite DB, so hitting KILL in
|
|
5
|
+
the dashboard genuinely stops a separate agent process on its next guarded call.
|
|
6
|
+
|
|
7
|
+
Auth: if `config.api_token` is set, every *mutating* endpoint (kill/unkill/policy/
|
|
8
|
+
approve) requires `Authorization: Bearer <token>`. Read endpoints stay open (intended
|
|
9
|
+
for a localhost bind). `sentinel serve` auto-generates a token if none is configured.
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import secrets
|
|
15
|
+
from collections import Counter
|
|
16
|
+
from typing import Optional
|
|
17
|
+
|
|
18
|
+
from fastapi import Body, Depends, FastAPI, Header, HTTPException
|
|
19
|
+
from fastapi.responses import HTMLResponse
|
|
20
|
+
|
|
21
|
+
from sentinel.approvals import Approvals
|
|
22
|
+
from sentinel.audit import AuditLog
|
|
23
|
+
from sentinel.config import Config
|
|
24
|
+
from sentinel.killswitch import KillSwitch
|
|
25
|
+
from sentinel.policy import Policy
|
|
26
|
+
|
|
27
|
+
_DASHBOARD_FILE = os.path.join(os.path.dirname(__file__), "dashboard", "index.html")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def create_app(config: Optional[Config] = None) -> FastAPI:
|
|
31
|
+
cfg = config or Config.from_env()
|
|
32
|
+
app = FastAPI(title="Sentinel Control Plane", version="0.1.0")
|
|
33
|
+
audit = AuditLog(cfg.db_path, redact_keys=cfg.redact_keys)
|
|
34
|
+
killswitch = KillSwitch(cfg.db_path)
|
|
35
|
+
approvals = Approvals(cfg.db_path)
|
|
36
|
+
|
|
37
|
+
def require_token(authorization: str = Header(default="")) -> None:
|
|
38
|
+
if not cfg.api_token:
|
|
39
|
+
return # auth disabled
|
|
40
|
+
if not secrets.compare_digest(authorization, f"Bearer {cfg.api_token}"):
|
|
41
|
+
raise HTTPException(status_code=401, detail="missing or invalid control token")
|
|
42
|
+
|
|
43
|
+
auth = [Depends(require_token)]
|
|
44
|
+
read_auth = auth if cfg.protect_reads else []
|
|
45
|
+
|
|
46
|
+
@app.get("/", response_class=HTMLResponse)
|
|
47
|
+
def dashboard() -> HTMLResponse:
|
|
48
|
+
with open(_DASHBOARD_FILE, "r", encoding="utf-8") as fh:
|
|
49
|
+
return HTMLResponse(fh.read())
|
|
50
|
+
|
|
51
|
+
@app.get("/api/status", dependencies=read_auth)
|
|
52
|
+
def status() -> dict:
|
|
53
|
+
v = audit.verify()
|
|
54
|
+
recs = audit.records()
|
|
55
|
+
return {
|
|
56
|
+
"integrity": {"ok": v.ok, "first_bad_seq": v.first_bad_seq, "message": v.message},
|
|
57
|
+
"killswitch": killswitch.status(),
|
|
58
|
+
"total_actions": len(recs),
|
|
59
|
+
"by_status": dict(Counter(r.status for r in recs)),
|
|
60
|
+
"by_decision": dict(Counter(r.decision for r in recs)),
|
|
61
|
+
"pending_approvals": len(approvals.pending()),
|
|
62
|
+
"auth_required": bool(cfg.api_token),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@app.get("/api/actions", dependencies=read_auth)
|
|
66
|
+
def actions(limit: int = 100) -> list:
|
|
67
|
+
recs = audit.records()[-limit:]
|
|
68
|
+
return [r.__dict__ for r in reversed(recs)]
|
|
69
|
+
|
|
70
|
+
@app.get("/api/verify", dependencies=read_auth)
|
|
71
|
+
def verify() -> dict:
|
|
72
|
+
v = audit.verify()
|
|
73
|
+
return {"ok": v.ok, "first_bad_seq": v.first_bad_seq, "message": v.message}
|
|
74
|
+
|
|
75
|
+
@app.get("/api/export", dependencies=read_auth)
|
|
76
|
+
def export() -> dict:
|
|
77
|
+
return audit.export()
|
|
78
|
+
|
|
79
|
+
@app.get("/api/approvals", dependencies=read_auth)
|
|
80
|
+
def list_approvals() -> list:
|
|
81
|
+
return approvals.pending()
|
|
82
|
+
|
|
83
|
+
@app.get("/api/policy", dependencies=read_auth)
|
|
84
|
+
def get_policy() -> dict:
|
|
85
|
+
try:
|
|
86
|
+
with open(cfg.policy_path, "r", encoding="utf-8") as fh:
|
|
87
|
+
text = fh.read()
|
|
88
|
+
except FileNotFoundError:
|
|
89
|
+
text = ""
|
|
90
|
+
return {"path": cfg.policy_path, "yaml": text}
|
|
91
|
+
|
|
92
|
+
@app.put("/api/policy", dependencies=auth)
|
|
93
|
+
def put_policy(payload: dict = Body(...)) -> dict:
|
|
94
|
+
text = payload.get("yaml", "")
|
|
95
|
+
try:
|
|
96
|
+
Policy.from_yaml(text) # validate before persisting
|
|
97
|
+
except Exception as exc: # surface parse error to the caller
|
|
98
|
+
raise HTTPException(status_code=400, detail=f"invalid policy: {exc}") from exc
|
|
99
|
+
with open(cfg.policy_path, "w", encoding="utf-8") as fh:
|
|
100
|
+
fh.write(text)
|
|
101
|
+
return {"ok": True}
|
|
102
|
+
|
|
103
|
+
@app.post("/api/kill", dependencies=auth)
|
|
104
|
+
def kill(payload: dict = Body(default={})) -> dict:
|
|
105
|
+
scope = payload.get("scope", "*")
|
|
106
|
+
reason = payload.get("reason", "killed via dashboard")
|
|
107
|
+
killswitch.arm(scope, reason=reason)
|
|
108
|
+
return {"ok": True, "killswitch": killswitch.status()}
|
|
109
|
+
|
|
110
|
+
@app.post("/api/unkill", dependencies=auth)
|
|
111
|
+
def unkill(payload: dict = Body(default={})) -> dict:
|
|
112
|
+
scope = payload.get("scope", "*")
|
|
113
|
+
killswitch.disarm(scope)
|
|
114
|
+
return {"ok": True, "killswitch": killswitch.status()}
|
|
115
|
+
|
|
116
|
+
@app.post("/api/approve", dependencies=auth)
|
|
117
|
+
def approve(payload: dict = Body(...)) -> dict:
|
|
118
|
+
approval_id = payload.get("id")
|
|
119
|
+
if not approval_id:
|
|
120
|
+
raise HTTPException(status_code=400, detail="missing approval id")
|
|
121
|
+
ok = approvals.approve(approval_id, by=payload.get("by", "dashboard"))
|
|
122
|
+
if not ok:
|
|
123
|
+
raise HTTPException(status_code=404, detail="no such pending approval")
|
|
124
|
+
return {"ok": True}
|
|
125
|
+
|
|
126
|
+
return app
|