watchlight-enclave 0.2.1__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.
@@ -0,0 +1,132 @@
1
+ Metadata-Version: 2.5
2
+ Name: watchlight-enclave
3
+ Version: 0.2.1
4
+ Summary: Watchlight AI Enclave — a governed, isolated runtime for autonomous AI agents.
5
+ Project-URL: Homepage, https://github.com/watchlight-ai-beacon/watchlight-enclave
6
+ Project-URL: Source, https://github.com/watchlight-ai-beacon/watchlight-enclave
7
+ Project-URL: Documentation, https://docs.watchlight.ai/enclave
8
+ Project-URL: Changelog, https://github.com/watchlight-ai-beacon/watchlight-enclave/blob/main/CHANGELOG.md
9
+ Project-URL: Issues, https://github.com/watchlight-ai-beacon/watchlight-enclave/issues
10
+ Project-URL: Security policy, https://github.com/watchlight-ai-beacon/watchlight-enclave/blob/main/SECURITY.md
11
+ Author: Watchlight AI
12
+ License: Apache-2.0
13
+ License-File: LICENSE
14
+ Keywords: agent-security,ai-agents,audit-trail,authorization,cedar,evidence,governance,sandbox
15
+ Classifier: Development Status :: 2 - Pre-Alpha
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: Apache Software License
18
+ Classifier: Operating System :: OS Independent
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Topic :: Security
25
+ Classifier: Topic :: Software Development :: Testing
26
+ Classifier: Topic :: System :: Monitoring
27
+ Classifier: Typing :: Typed
28
+ Requires-Python: >=3.10
29
+ Requires-Dist: cryptography>=42.0
30
+ Requires-Dist: pyyaml>=6.0
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=8.3.4; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Watchlight AI Enclave
36
+
37
+ **Run an agent in a box it cannot talk its way out of, and get the evidence
38
+ your security review asks for — checkable offline, by someone who doesn't trust
39
+ you.**
40
+
41
+ You hand an agent a repo and a task. It can edit files, call tools, and reach
42
+ the network. Two questions follow immediately, and neither is answerable after
43
+ the fact by reading logs the agent could have written:
44
+
45
+ - **What did it actually try to reach?**
46
+ - **What was it allowed to do, and who decided?**
47
+
48
+ Enclave runs the agent in an isolated sandbox whose only route out is a
49
+ recording egress guard, and seals what happened into a hash-chained evidence
50
+ bundle you can hand to someone who doesn't trust you.
51
+
52
+ ```bash
53
+ pip install watchlight-enclave
54
+ ```
55
+
56
+ ```bash
57
+ wl-enclave init # writes enclave.yaml, scaffolds a policy
58
+ wl-enclave keygen # one key, once; runs seal signed bundles
59
+ wl-enclave run --purpose "Fix PR #412" # runs the agent in a sandbox
60
+ wl-enclave verify runs/<id>/bundle # checks the evidence, offline
61
+ wl-enclave hosts --since 2026-11-03 # what did it actually reach?
62
+ ```
63
+
64
+ That last one is the question a security review opens with, and the answer comes
65
+ out of verified bundles rather than out of the agent's own logs:
66
+
67
+ ```text
68
+ $ wl-enclave hosts --since 2026-11-03
69
+ wl-enclave: runs 14 verified
70
+ wl-enclave: coverage http_connect only; icmp, raw_tcp, udp had no route and are not recorded
71
+
72
+ HOST PORT VERDICT TRIES SENT RECV LAST IP
73
+ pastebin.com 443 deny 20 - - -
74
+ example.com 443 allow 20 34.4 kB 128.2 kB 172.66.147.243
75
+
76
+ wl-enclave: 2 host/verdict pair(s) over 40 attempt(s)
77
+ ```
78
+
79
+ If a run's bundle doesn't verify, its hosts are left out of that table **and
80
+ the count above it says so**. A short host list is the one way this command
81
+ could mislead you, so it refuses to be quietly short.
82
+
83
+ One rule drives the whole design: **a bundle must never be able to understate
84
+ what happened.** A bundle that quietly drops records while still looking
85
+ complete is worse than one that admits a gap. The first gets a reviewer to sign
86
+ off; the second gets them to ask a question. That's why `verify` gives four
87
+ answers instead of two: `failed`, `uncontained`, `incomplete`, `ok`. Only `ok`
88
+ exits 0.
89
+
90
+ `verify` needs no account, no network and no Watchlight.
91
+
92
+ ## Requirements
93
+
94
+ Python 3.10+, and a container runtime (Docker or Colima) for `run`. `verify`
95
+ needs neither.
96
+
97
+ ## Documentation
98
+
99
+ Everything lives in the repository: the quickstart, what a bundle proves, the
100
+ trust boundaries, the control vocabulary, egress coverage, and how to write a
101
+ driver for a new sandbox.
102
+
103
+ **Documentation: https://docs.watchlight.ai/enclave**
104
+
105
+ **Source: https://github.com/watchlight-ai-beacon/watchlight-enclave**
106
+
107
+ - [Quickstart](https://github.com/watchlight-ai-beacon/watchlight-enclave/blob/main/docs/README.md)
108
+ - [What a bundle proves, and what it does not](https://github.com/watchlight-ai-beacon/watchlight-enclave/blob/main/docs/design/evidence.md)
109
+ - [Changelog](https://github.com/watchlight-ai-beacon/watchlight-enclave/blob/main/CHANGELOG.md) — including the three contracts this project versions separately
110
+ - [Security policy](https://github.com/watchlight-ai-beacon/watchlight-enclave/blob/main/SECURITY.md)
111
+
112
+ ## Status
113
+
114
+ Early development, pre-1.0. The CLI, the `enclave.yaml` schema and how strictly
115
+ `verify` reads a bundle can each change in a minor release, and the changelog
116
+ always says which of the three moved. 1.0 waits on the manifest reaching its
117
+ final shape.
118
+
119
+ One limit worth knowing up front. A signature means *this bundle is the one
120
+ that key sealed, and nobody has touched it since*. It does not mean *this
121
+ bundle is everything that happened*. Whoever holds the key can cut the chain
122
+ short and re-seal it, which is why the format already carries a `cosignatures`
123
+ slot for a witness it doesn't have yet. The repository is blunt about this one
124
+ and the rest of the known gaps.
125
+
126
+ ## License
127
+
128
+ Apache-2.0. The CLI, the evidence format and its offline verifier are all open.
129
+ Two compiled dependencies — the Cedar decision engine and the MCP policy
130
+ enforcement runtime — ship under the
131
+ [Watchlight Developer Edition license](https://github.com/watchlight-ai-beacon/watchlight-de),
132
+ free to use including in production and commercially.
@@ -0,0 +1,16 @@
1
+ wl_enclave/__init__.py,sha256=4v_cEYS5BFJ0KNnqIUzWHa7am0X4dcSiB9tNvI_G5-E,348
2
+ wl_enclave/attestation.py,sha256=J0y9JEbyiWAKS5JfUp5AwmyI4sgPkqfAxzEblIL3xZQ,10066
3
+ wl_enclave/cli.py,sha256=x7RYX0z4R46kxxsASMLt8syDr-ImhLeOeurswdXCmyU,45182
4
+ wl_enclave/config.py,sha256=yfhts5dFH6N7MJq11lhQ1VO7T6tLmkg4D55HNzG6YEg,14151
5
+ wl_enclave/evidence.py,sha256=JPQTv3Efeyjh5Aoqwu5O6cyyNzl3mmTCj4okBKO2ofQ,36645
6
+ wl_enclave/runs.py,sha256=XhXY5IW0mlsP4L05JZcuQHjPx30sbBlRWRFFlm1A-fA,9398
7
+ wl_enclave/signing.py,sha256=uC4JDxNnIpLfNdCqn2RXE_cMRd8eouYPkglGtLw0q_Q,14291
8
+ wl_enclave/drivers/__init__.py,sha256=bO9-bOa-fDs6QnbnwoLoFDC2SJbEslZ0aUyJ_Or2n0U,12904
9
+ wl_enclave/drivers/docker.py,sha256=ZscTtxgeT4K1OksizjxfP3ILTt8VL7NK1AKZqe660uA,29107
10
+ wl_enclave/egress/__init__.py,sha256=G9EOfeyplw7k2vVHqoc--leBsJPiYAixa58bj04-hbI,11567
11
+ wl_enclave/egress/local.py,sha256=4EDHOvIYvk6_cAvaFo-fiArBdGo8gjJp98nJaQGfy9g,24785
12
+ watchlight_enclave-0.2.1.dist-info/METADATA,sha256=rnkh4zeZ7KiMWHnhkzU_LVyrP1UbM7DamBcsgojArJs,6034
13
+ watchlight_enclave-0.2.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
14
+ watchlight_enclave-0.2.1.dist-info/entry_points.txt,sha256=r2o6d_3GxpiijrCorzJdP75C215rlvj9s9uKa8fQRTY,51
15
+ watchlight_enclave-0.2.1.dist-info/licenses/LICENSE,sha256=tNyAse8BZHonpskyCo-cDwokh5yPmpExEtxAJfirYH8,11343
16
+ watchlight_enclave-0.2.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ wl-enclave = wl_enclave.cli:main
@@ -0,0 +1,201 @@
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,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Watchlight AI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
wl_enclave/__init__.py ADDED
@@ -0,0 +1,8 @@
1
+ """Watchlight AI Enclave — a governed, isolated runtime for autonomous AI agents.
2
+
3
+ Two layers enforce on every run. The :mod:`~wl_enclave.drivers` runtime decides
4
+ where the agent may connect; Watchlight decides what authority it has. Both are
5
+ recorded in one hash-chained evidence bundle (:mod:`~wl_enclave.evidence`).
6
+ """
7
+
8
+ __version__ = "0.2.1"
@@ -0,0 +1,263 @@
1
+ """The vocabulary an attestation uses to name individual controls.
2
+
3
+ An attestation used to collapse a layer's enforcement into one boolean —
4
+ ``route_exclusive`` for the guard, a handful of settings for the sandbox. That
5
+ is enough to say a layer held, and not enough to say *what* held. When a
6
+ reviewer asks why a bundle is weaker than they expected, the answer is always
7
+ about one specific control, and a boolean cannot carry it.
8
+
9
+ So each control is named, and each says two things: whether it was in force,
10
+ and how that was established. The second half is the point. A control read back
11
+ out of the runtime and a control we merely asked for are both "configured", and
12
+ in a bundle they are indistinguishable unless the record says which it was.
13
+
14
+ Three states, and they map onto the verdict :func:`wl_enclave.evidence.verify`
15
+ already produces rather than introducing a severity scale beside it:
16
+
17
+ ``in_force=True``
18
+ Established. Contributes nothing to the verdict; this is the normal case.
19
+
20
+ ``in_force=False``
21
+ The control was not in force. The layer did not hold, so the run is not
22
+ attested — the caller raises this as a problem.
23
+
24
+ ``in_force=None``
25
+ Could not be determined. The control may well have held; we cannot say.
26
+ This lands on ``incomplete``, which already means "everything here is true
27
+ and some of what happened may be missing" — the same verdict a dropped
28
+ record produces, for the same reason.
29
+
30
+ The names are constants because two layers emit them and one verifier reads
31
+ them. A control renamed on one side only would silently stop being checked,
32
+ which is the failure mode the closed record-type set exists to prevent for
33
+ record types.
34
+ """
35
+
36
+ from __future__ import annotations
37
+
38
+ from typing import Optional
39
+
40
+ __all__ = [
41
+ "READBACK",
42
+ "REQUESTED",
43
+ "RUNTIME_CONFIG",
44
+ "TOPOLOGY",
45
+ "NETWORK_UNROUTABLE",
46
+ "SANDBOX_SINGLE_NETWORK",
47
+ "SANDBOX_ON_INTENDED_NETWORK",
48
+ "GUARD_ATTACHED",
49
+ "GUARD_HAS_EGRESS",
50
+ "GUARD_LIVE",
51
+ "ROOTFS_READ_ONLY",
52
+ "CAPABILITIES_DROPPED",
53
+ "NO_NEW_PRIVILEGES",
54
+ "RUNS_AS_NON_ROOT",
55
+ "EVIDENCE_MASKED",
56
+ "control",
57
+ "merge",
58
+ "unverified_controls",
59
+ "failed_controls",
60
+ "unrecognised_controls",
61
+ "claim_of",
62
+ "establishes",
63
+ "CONTAINMENT",
64
+ "WITNESSING",
65
+ ]
66
+
67
+ # -- how a control's state was established --------------------------------
68
+
69
+ #: Read out of the running system after the fact. The strongest thing we say.
70
+ READBACK = "runtime_readback"
71
+
72
+ #: Asked for at creation and not read back. Honest but weaker: a setting
73
+ #: applied and never confirmed is indistinguishable from one never applied.
74
+ REQUESTED = "requested_not_readback"
75
+
76
+ #: Read back from the runtime's record of the container's configuration. In
77
+ #: between the two above, and worth its own name: it is not our own argv echoed
78
+ #: back, so it catches a setting that never reached the daemon — but it is the
79
+ #: daemon's account of what was asked for, not the kernel's account of what is
80
+ #: in force. A mount destination, for instance, is normalised by the daemon
81
+ #: after this record is made.
82
+ RUNTIME_CONFIG = "runtime_config_readback"
83
+
84
+ #: True by construction rather than by inspection — there is no route to read
85
+ #: back because the topology never created one.
86
+ TOPOLOGY = "network_topology"
87
+
88
+ # -- control names, shared by every layer that attests ---------------------
89
+
90
+ NETWORK_UNROUTABLE = "network_unroutable"
91
+ SANDBOX_SINGLE_NETWORK = "sandbox_single_network"
92
+ SANDBOX_ON_INTENDED_NETWORK = "sandbox_on_intended_network"
93
+ GUARD_ATTACHED = "guard_attached"
94
+ GUARD_HAS_EGRESS = "guard_has_egress"
95
+ GUARD_LIVE = "guard_live_at_readback"
96
+ ROOTFS_READ_ONLY = "rootfs_read_only"
97
+ CAPABILITIES_DROPPED = "capabilities_dropped"
98
+ NO_NEW_PRIVILEGES = "no_new_privileges"
99
+ RUNS_AS_NON_ROOT = "runs_as_non_root"
100
+ EVIDENCE_MASKED = "evidence_masked_from_sandbox"
101
+
102
+
103
+ def control(
104
+ in_force: Optional[bool], verified_by: str, detail: str = ""
105
+ ) -> dict:
106
+ """One control's state, as it appears in an attestation record.
107
+
108
+ ``detail`` is for the thing a reviewer would otherwise have to reconstruct
109
+ — which extra network was attached, what the guard exited with. It is
110
+ omitted when empty rather than carried as a null, so a record stays
111
+ readable at a glance.
112
+ """
113
+ entry: dict = {"in_force": in_force, "verified_by": verified_by}
114
+ if detail:
115
+ entry["detail"] = detail
116
+ return entry
117
+
118
+
119
+ # -- which claim a control's failure belongs to ---------------------------
120
+
121
+ #: A failure here means the sandbox was less isolated than intended.
122
+ CONTAINMENT = "containment"
123
+
124
+ #: A failure here means the run was less *observed* than intended. Distinct
125
+ #: from containment because the two move independently and sometimes in
126
+ #: opposite directions: a guard that dies on an internal network leaves the
127
+ #: sandbox able to reach nothing at all, so the run is strictly more contained
128
+ #: and strictly less witnessed. Reporting that as a containment failure sends
129
+ #: an operator to look for an escaped agent when the truth is that the witness
130
+ #: died, and it spends the one alarm that should mean "isolation failed".
131
+ WITNESSING = "witnessing"
132
+
133
+ _CLAIM = {
134
+ NETWORK_UNROUTABLE: CONTAINMENT,
135
+ SANDBOX_SINGLE_NETWORK: CONTAINMENT,
136
+ SANDBOX_ON_INTENDED_NETWORK: CONTAINMENT,
137
+ ROOTFS_READ_ONLY: CONTAINMENT,
138
+ CAPABILITIES_DROPPED: CONTAINMENT,
139
+ NO_NEW_PRIVILEGES: CONTAINMENT,
140
+ RUNS_AS_NON_ROOT: CONTAINMENT,
141
+ EVIDENCE_MASKED: CONTAINMENT,
142
+ GUARD_ATTACHED: WITNESSING,
143
+ GUARD_HAS_EGRESS: WITNESSING,
144
+ GUARD_LIVE: WITNESSING,
145
+ }
146
+
147
+
148
+ def claim_of(name: str) -> Optional[str]:
149
+ """Which claim a control bears on, or ``None`` if this build has no idea.
150
+
151
+ An unrecognised name is not silently sorted into one bucket. A verifier
152
+ that guesses would either raise a containment alarm for something it cannot
153
+ describe, or quietly discount a real one.
154
+ """
155
+ return _CLAIM.get(name)
156
+
157
+
158
+ # -- how strongly a control's state was established -----------------------
159
+
160
+ #: How strong each state is. Lower is weaker, and weaker wins a merge.
161
+ _STRENGTH = {False: 0, None: 1, True: 2}
162
+
163
+ #: How strong each provenance is, on its own axis. ``REQUESTED`` is the one
164
+ #: that does not establish anything: the module's whole premise is that a
165
+ #: setting applied and never confirmed is indistinguishable from one never
166
+ #: applied, so a control resting on it has not been established whatever its
167
+ #: ``in_force`` says.
168
+ _PROVENANCE = {
169
+ READBACK: 3,
170
+ TOPOLOGY: 3,
171
+ RUNTIME_CONFIG: 2,
172
+ REQUESTED: 1,
173
+ }
174
+
175
+
176
+ def establishes(entry: dict) -> bool:
177
+ """Whether this entry's provenance is strong enough to establish anything.
178
+
179
+ False for ``requested_not_readback``, and false for a provenance string
180
+ this build does not recognise — an unknown label cannot be assumed to be
181
+ one of the strong ones, and a driver inventing its own must not be able to
182
+ buy a stronger reading than the vocabulary grants.
183
+ """
184
+ return _PROVENANCE.get(entry.get("verified_by"), 0) >= 2
185
+
186
+
187
+ def merge(into: dict, new: dict) -> dict:
188
+ """Fold one layer's controls into the running set, weakest claim winning.
189
+
190
+ Order-independent on purpose. A run has more than one attesting moment —
191
+ the topology is read when the sandbox is provisioned, the guard's fate is
192
+ known only at the end — and taking the latest would let anything able to
193
+ append a record overwrite a finding with a more flattering one. Taking the
194
+ *weakest* cannot be abused in that direction: an attacker who can append
195
+ records can only make the bundle describe a worse run than happened, which
196
+ is the one direction that does not mislead a reviewer.
197
+
198
+ It also gets the honest answer here for free. ``guard_live_at_readback``
199
+ was genuinely in force when the topology was read and genuinely false by
200
+ the end; the second fact is the one that bears on the evidence.
201
+ """
202
+ def rank(entry: dict) -> tuple[int, int]:
203
+ # Both axes, weakest first. Ranking on in_force alone let the first
204
+ # record's provenance win whenever two layers agreed on the state —
205
+ # so a control read back out of the runtime could be replaced by one
206
+ # merely asked for, with no visible change.
207
+ return (
208
+ _STRENGTH.get(entry.get("in_force"), 1),
209
+ _PROVENANCE.get(entry.get("verified_by"), 0),
210
+ )
211
+
212
+ merged = dict(into)
213
+ for name, entry in (new or {}).items():
214
+ if not isinstance(entry, dict):
215
+ continue
216
+ held = merged.get(name)
217
+ if held is None or rank(entry) < rank(held):
218
+ merged[name] = entry
219
+ return merged
220
+
221
+
222
+ def unverified_controls(controls: dict) -> list[str]:
223
+ """Names of controls whose state could not be determined.
224
+
225
+ These are why a bundle reads ``incomplete`` rather than ``ok``: nothing in
226
+ it is false, and something in it is unknown.
227
+ """
228
+ return sorted(
229
+ name
230
+ for name, entry in (controls or {}).items()
231
+ if isinstance(entry, dict)
232
+ and (entry.get("in_force") is None or not establishes(entry))
233
+ )
234
+
235
+
236
+ def failed_controls(controls: dict, claim: Optional[str] = None) -> list[str]:
237
+ """Names of controls established as *not* in force.
238
+
239
+ ``claim`` narrows the result to one kind of failure. Callers want this
240
+ split because the two kinds reach different verdicts — see
241
+ :data:`CONTAINMENT` and :data:`WITNESSING`.
242
+ """
243
+ return sorted(
244
+ name
245
+ for name, entry in (controls or {}).items()
246
+ if isinstance(entry, dict)
247
+ and entry.get("in_force") is False
248
+ and (claim is None or claim_of(name) == claim)
249
+ )
250
+
251
+
252
+ def unrecognised_controls(controls: dict) -> list[str]:
253
+ """Names this build cannot place in either claim.
254
+
255
+ Reported rather than bucketed. The constants exist so that one verifier
256
+ reads what several layers write; a name outside the set means the two have
257
+ drifted, and a verifier that guessed would hide exactly that.
258
+ """
259
+ return sorted(
260
+ name
261
+ for name in (controls or {})
262
+ if claim_of(name) is None
263
+ )