@provos/ironcurtain 0.1.0

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.
Files changed (160) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +311 -0
  3. package/dist/agent/index.d.ts +10 -0
  4. package/dist/agent/index.js +71 -0
  5. package/dist/agent/index.js.map +1 -0
  6. package/dist/agent/prompts.d.ts +5 -0
  7. package/dist/agent/prompts.js +26 -0
  8. package/dist/agent/prompts.js.map +1 -0
  9. package/dist/agent/tools.d.ts +13 -0
  10. package/dist/agent/tools.js +51 -0
  11. package/dist/agent/tools.js.map +1 -0
  12. package/dist/cli.d.ts +2 -0
  13. package/dist/cli.js +78 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/config/constitution.md +16 -0
  16. package/dist/config/generated/compiled-policy.json +236 -0
  17. package/dist/config/generated/test-scenarios.json +765 -0
  18. package/dist/config/generated/tool-annotations.json +955 -0
  19. package/dist/config/index.d.ts +25 -0
  20. package/dist/config/index.js +151 -0
  21. package/dist/config/index.js.map +1 -0
  22. package/dist/config/mcp-servers.json +22 -0
  23. package/dist/config/model-provider.d.ts +49 -0
  24. package/dist/config/model-provider.js +78 -0
  25. package/dist/config/model-provider.js.map +1 -0
  26. package/dist/config/paths.d.ts +59 -0
  27. package/dist/config/paths.js +96 -0
  28. package/dist/config/paths.js.map +1 -0
  29. package/dist/config/types.d.ts +89 -0
  30. package/dist/config/types.js +2 -0
  31. package/dist/config/types.js.map +1 -0
  32. package/dist/config/user-config.d.ts +93 -0
  33. package/dist/config/user-config.js +309 -0
  34. package/dist/config/user-config.js.map +1 -0
  35. package/dist/hash.d.ts +17 -0
  36. package/dist/hash.js +34 -0
  37. package/dist/hash.js.map +1 -0
  38. package/dist/index.d.ts +1 -0
  39. package/dist/index.js +61 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/logger.d.ts +11 -0
  42. package/dist/logger.js +93 -0
  43. package/dist/logger.js.map +1 -0
  44. package/dist/pipeline/annotate.d.ts +9 -0
  45. package/dist/pipeline/annotate.js +136 -0
  46. package/dist/pipeline/annotate.js.map +1 -0
  47. package/dist/pipeline/compile.d.ts +23 -0
  48. package/dist/pipeline/compile.js +386 -0
  49. package/dist/pipeline/compile.js.map +1 -0
  50. package/dist/pipeline/constitution-compiler.d.ts +22 -0
  51. package/dist/pipeline/constitution-compiler.js +197 -0
  52. package/dist/pipeline/constitution-compiler.js.map +1 -0
  53. package/dist/pipeline/generate-with-repair.d.ts +22 -0
  54. package/dist/pipeline/generate-with-repair.js +64 -0
  55. package/dist/pipeline/generate-with-repair.js.map +1 -0
  56. package/dist/pipeline/handwritten-scenarios.d.ts +9 -0
  57. package/dist/pipeline/handwritten-scenarios.js +321 -0
  58. package/dist/pipeline/handwritten-scenarios.js.map +1 -0
  59. package/dist/pipeline/llm-logger.d.ts +42 -0
  60. package/dist/pipeline/llm-logger.js +78 -0
  61. package/dist/pipeline/llm-logger.js.map +1 -0
  62. package/dist/pipeline/pipeline-shared.d.ts +47 -0
  63. package/dist/pipeline/pipeline-shared.js +145 -0
  64. package/dist/pipeline/pipeline-shared.js.map +1 -0
  65. package/dist/pipeline/policy-verifier.d.ts +46 -0
  66. package/dist/pipeline/policy-verifier.js +277 -0
  67. package/dist/pipeline/policy-verifier.js.map +1 -0
  68. package/dist/pipeline/scenario-generator.d.ts +11 -0
  69. package/dist/pipeline/scenario-generator.js +128 -0
  70. package/dist/pipeline/scenario-generator.js.map +1 -0
  71. package/dist/pipeline/tool-annotator.d.ts +24 -0
  72. package/dist/pipeline/tool-annotator.js +201 -0
  73. package/dist/pipeline/tool-annotator.js.map +1 -0
  74. package/dist/pipeline/types.d.ts +122 -0
  75. package/dist/pipeline/types.js +10 -0
  76. package/dist/pipeline/types.js.map +1 -0
  77. package/dist/sandbox/index.d.ts +39 -0
  78. package/dist/sandbox/index.js +178 -0
  79. package/dist/sandbox/index.js.map +1 -0
  80. package/dist/session/agent-session.d.ts +83 -0
  81. package/dist/session/agent-session.js +382 -0
  82. package/dist/session/agent-session.js.map +1 -0
  83. package/dist/session/cli-transport.d.ts +61 -0
  84. package/dist/session/cli-transport.js +320 -0
  85. package/dist/session/cli-transport.js.map +1 -0
  86. package/dist/session/errors.d.ts +19 -0
  87. package/dist/session/errors.js +33 -0
  88. package/dist/session/errors.js.map +1 -0
  89. package/dist/session/index.d.ts +29 -0
  90. package/dist/session/index.js +104 -0
  91. package/dist/session/index.js.map +1 -0
  92. package/dist/session/message-compactor.d.ts +32 -0
  93. package/dist/session/message-compactor.js +81 -0
  94. package/dist/session/message-compactor.js.map +1 -0
  95. package/dist/session/prompts.d.ts +5 -0
  96. package/dist/session/prompts.js +62 -0
  97. package/dist/session/prompts.js.map +1 -0
  98. package/dist/session/resource-budget-tracker.d.ts +124 -0
  99. package/dist/session/resource-budget-tracker.js +327 -0
  100. package/dist/session/resource-budget-tracker.js.map +1 -0
  101. package/dist/session/step-loop-detector.d.ts +63 -0
  102. package/dist/session/step-loop-detector.js +136 -0
  103. package/dist/session/step-loop-detector.js.map +1 -0
  104. package/dist/session/transport.d.ts +24 -0
  105. package/dist/session/transport.js +2 -0
  106. package/dist/session/transport.js.map +1 -0
  107. package/dist/session/truncate-result.d.ts +35 -0
  108. package/dist/session/truncate-result.js +71 -0
  109. package/dist/session/truncate-result.js.map +1 -0
  110. package/dist/session/types.d.ts +220 -0
  111. package/dist/session/types.js +6 -0
  112. package/dist/session/types.js.map +1 -0
  113. package/dist/trusted-process/audit-log.d.ts +7 -0
  114. package/dist/trusted-process/audit-log.js +21 -0
  115. package/dist/trusted-process/audit-log.js.map +1 -0
  116. package/dist/trusted-process/call-circuit-breaker.d.ts +33 -0
  117. package/dist/trusted-process/call-circuit-breaker.js +61 -0
  118. package/dist/trusted-process/call-circuit-breaker.js.map +1 -0
  119. package/dist/trusted-process/escalation.d.ts +7 -0
  120. package/dist/trusted-process/escalation.js +38 -0
  121. package/dist/trusted-process/escalation.js.map +1 -0
  122. package/dist/trusted-process/index.d.ts +32 -0
  123. package/dist/trusted-process/index.js +151 -0
  124. package/dist/trusted-process/index.js.map +1 -0
  125. package/dist/trusted-process/mcp-client-manager.d.ts +25 -0
  126. package/dist/trusted-process/mcp-client-manager.js +90 -0
  127. package/dist/trusted-process/mcp-client-manager.js.map +1 -0
  128. package/dist/trusted-process/mcp-proxy-server.d.ts +24 -0
  129. package/dist/trusted-process/mcp-proxy-server.js +451 -0
  130. package/dist/trusted-process/mcp-proxy-server.js.map +1 -0
  131. package/dist/trusted-process/path-utils.d.ts +50 -0
  132. package/dist/trusted-process/path-utils.js +158 -0
  133. package/dist/trusted-process/path-utils.js.map +1 -0
  134. package/dist/trusted-process/policy-engine.d.ts +88 -0
  135. package/dist/trusted-process/policy-engine.js +523 -0
  136. package/dist/trusted-process/policy-engine.js.map +1 -0
  137. package/dist/trusted-process/policy-roots.d.ts +50 -0
  138. package/dist/trusted-process/policy-roots.js +67 -0
  139. package/dist/trusted-process/policy-roots.js.map +1 -0
  140. package/dist/trusted-process/policy-types.d.ts +6 -0
  141. package/dist/trusted-process/policy-types.js +2 -0
  142. package/dist/trusted-process/policy-types.js.map +1 -0
  143. package/dist/trusted-process/sandbox-integration.d.ts +92 -0
  144. package/dist/trusted-process/sandbox-integration.js +184 -0
  145. package/dist/trusted-process/sandbox-integration.js.map +1 -0
  146. package/dist/types/argument-roles.d.ts +112 -0
  147. package/dist/types/argument-roles.js +344 -0
  148. package/dist/types/argument-roles.js.map +1 -0
  149. package/dist/types/audit.d.ts +18 -0
  150. package/dist/types/audit.js +2 -0
  151. package/dist/types/audit.js.map +1 -0
  152. package/dist/types/mcp.d.ts +20 -0
  153. package/dist/types/mcp.js +2 -0
  154. package/dist/types/mcp.js.map +1 -0
  155. package/package.json +83 -0
  156. package/src/config/constitution.md +16 -0
  157. package/src/config/generated/compiled-policy.json +236 -0
  158. package/src/config/generated/test-scenarios.json +765 -0
  159. package/src/config/generated/tool-annotations.json +955 -0
  160. package/src/config/mcp-servers.json +22 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Niels Provos
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,311 @@
1
+ # IronCurtain
2
+
3
+ **A secure runtime for autonomous AI agents, where security policy is derived from a human-readable constitution.**
4
+
5
+ > **Research Prototype.** IronCurtain is an early-stage research project exploring how to make AI agents safe enough to be genuinely useful. APIs, configuration formats, and architecture may change. Contributions and feedback are welcome.
6
+
7
+ ## The Problem
8
+
9
+ Autonomous AI agents can manage files, run git commands, send messages, and interact with APIs on your behalf. But today's agent frameworks give the agent the same privileges as the user such as full access to the filesystem, credentials, and network. Security researchers call this **ambient authority**, and it means a single prompt injection or multi-turn drift can cause an agent to delete files, exfiltrate data, or push malicious code.
10
+
11
+ The common response is to either restrict agents to a narrow sandbox (limiting their usefulness) or to ask the user to approve every action (limiting their autonomy). Neither is satisfactory.
12
+
13
+ ## The Approach
14
+
15
+ IronCurtain takes a different path: **express your security intent in plain English, then let the system figure out enforcement.**
16
+
17
+ You write a **constitution** which is a short document describing what your agent is and isn't allowed to do. IronCurtain compiles this into a deterministic security policy using an LLM pipeline, validates the compiled rules against generated test scenarios, and then enforces the policy at runtime on every tool call. The result is an agent that can work autonomously within boundaries you define in natural language.
18
+
19
+ The key ideas:
20
+
21
+ - **The agent is untrusted.** IronCurtain assumes the LLM may be compromised by prompt injection or drift. Security does not depend on the model "being good."
22
+ - **English in, enforcement out.** You write intent ("no destructive git operations without approval"); the system compiles it into deterministic rules that are enforced without further LLM involvement at runtime.
23
+ - **Semantic interposition.** Instead of giving the agent raw system access, all interactions go through [MCP](https://modelcontextprotocol.io/) servers (filesystem, git, etc.). Every tool call passes through a policy engine that can **allow**, **deny**, or **escalate** to the user for approval.
24
+ - **Defense in depth.** Agent code runs in a V8 isolate with no direct access to the host. The only way out is through semantically meaningful MCP tool calls and every one is checked against policy.
25
+
26
+ ## Architecture
27
+
28
+ ```
29
+ ┌─────────────────────────────────────────────┐
30
+ │ Agent (LLM) │
31
+ │ Generates TypeScript to accomplish tasks │
32
+ └──────────────────┬──────────────────────────┘
33
+ │ TypeScript code
34
+
35
+ ┌─────────────────────────────────────────────┐
36
+ │ V8 Isolated Sandbox │
37
+ │ Code executes in isolation. │
38
+ │ Only interface to the world: typed │
39
+ │ function stubs that produce MCP requests. │
40
+ │ │
41
+ │ filesystem.read_file({path: '...'}) │
42
+ │ git.status({repo_path: '...'}) │
43
+ └──────────────────┬──────────────────────────┘
44
+ │ MCP tool-call requests
45
+
46
+ ┌─────────────────────────────────────────────┐
47
+ │ Trusted Process (MCP Proxy) │
48
+ │ │
49
+ │ ┌───────────────────────────────────────┐ │
50
+ │ │ Policy Engine │ │
51
+ │ │ 1. Structural invariants (hardcoded) │ │
52
+ │ │ 2. Compiled constitution rules │ │
53
+ │ │ → allow / deny / escalate │ │
54
+ │ └───────────────────────────────────────┘ │
55
+ │ ┌──────────────┐ ┌─────────────────────┐ │
56
+ │ │ Audit Log │ │ Escalation Handler │ │
57
+ │ │ (JSONL) │ │ (human approval) │ │
58
+ │ └──────────────┘ └─────────────────────┘ │
59
+ └──────────────────┬──────────────────────────┘
60
+ │ approved calls only
61
+
62
+ ┌──────────┐ ┌──────────┐ ┌──────────┐
63
+ │Filesystem│ │ Git │ │ Other │
64
+ │MCP Server│ │MCP Server│ │MCP Server│
65
+ └──────────┘ └──────────┘ └──────────┘
66
+ ```
67
+
68
+ **Four layers, strict trust boundaries:**
69
+
70
+ 1. **Agent** -- An LLM (Claude, GPT, Gemini) that writes TypeScript to accomplish user tasks. It has no direct access to the system.
71
+ 2. **Sandbox** -- A V8 isolate ([UTCP Code Mode](https://utcp.dev/)) that executes the agent's TypeScript. The only way to interact with the outside world is through typed function stubs that produce structured MCP requests.
72
+ 3. **Trusted Process** -- The security kernel. Every MCP request from the sandbox passes through a two-phase policy engine before reaching any real server. Phase 1 enforces hardcoded structural invariants (protected paths, unknown tool denial). Phase 2 evaluates the compiled constitution rules. Denied calls are blocked; escalated calls are presented to the user for approval.
73
+ 4. **MCP Servers** -- Standard [Model Context Protocol](https://modelcontextprotocol.io/) servers that provide filesystem access, git operations, and other capabilities. Only approved requests reach them.
74
+
75
+ ## Policy Compilation Pipeline
76
+
77
+ The constitution is compiled into enforceable policy through a four-stage LLM pipeline:
78
+
79
+ ```
80
+ constitution.md → [Annotate] → [Compile] → [Generate Scenarios] → [Verify & Repair]
81
+ │ │ │ │
82
+ ▼ ▼ ▼ ▼
83
+ tool-annotations compiled-policy test-scenarios verified policy
84
+ .json .json .json (or build failure)
85
+ ```
86
+
87
+ 1. **Annotate** -- Classify each MCP tool's arguments by role (read-path, write-path, delete-path, none).
88
+ 2. **Compile** -- Translate the English constitution into deterministic if/then rules.
89
+ 3. **Generate Scenarios** -- Create test scenarios from the constitution, combined with mandatory handwritten invariant tests.
90
+ 4. **Verify & Repair** -- Execute scenarios against the real policy engine. An LLM judge analyzes failures and generates targeted repairs (up to 2 rounds). The build fails if the policy cannot be verified.
91
+
92
+ All artifacts are content-hash cached -- only changed inputs trigger recompilation.
93
+
94
+ ## Getting Started
95
+
96
+ ### Prerequisites
97
+
98
+ - Node.js 18+
99
+ - An API key for at least one supported LLM provider (Anthropic, Google, or OpenAI)
100
+
101
+ ### Install
102
+
103
+ **As a global CLI tool (end users):**
104
+
105
+ ```bash
106
+ npm install -g ironcurtain
107
+ ```
108
+
109
+ **From source (development):**
110
+
111
+ ```bash
112
+ git clone https://github.com/provos/ironcurtain.git
113
+ cd ironcurtain
114
+ npm install
115
+ ```
116
+
117
+ ### 1. Configure your API key
118
+
119
+ Set your LLM provider API key via environment variable:
120
+
121
+ ```bash
122
+ export ANTHROPIC_API_KEY=sk-ant-...
123
+ ```
124
+
125
+ Or add it to `~/.ironcurtain/config.json` (auto-created on first run with defaults):
126
+
127
+ ```json
128
+ {
129
+ "anthropicApiKey": "sk-ant-..."
130
+ }
131
+ ```
132
+
133
+ Environment variables take precedence over config file values. Supported providers: `ANTHROPIC_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`, `OPENAI_API_KEY`.
134
+
135
+ ### 2. Write your constitution
136
+
137
+ Edit `src/config/constitution.md` to express your security policy in plain English. Here's the included example:
138
+
139
+ ```markdown
140
+ # Guiding Principles
141
+
142
+ 1. **Least privilege**: The agent may only access resources explicitly permitted by policy.
143
+ 2. **No destruction**: Delete operations outside the sandbox are never permitted.
144
+ 3. **Human oversight**: Operations outside the sandbox require explicit human approval.
145
+
146
+ # Concrete Guidance
147
+
148
+ - The agent is allowed to read, write and delete content in the Downloads folder.
149
+ - The agent is allowed to read documents in the User's document folder.
150
+ - The agent may perform read-only git operations (status, diff, log) within the sandbox without approval.
151
+ - The agent may stage files (git add) and commit within the sandbox without approval.
152
+ - The agent must receive human approval before git push, pull, fetch, or any remote-contacting operation.
153
+ - The agent must receive human approval before git reset, rebase, merge, or any history-rewriting operation.
154
+ ```
155
+
156
+ ### 3. Annotate tools and compile the policy
157
+
158
+ ```bash
159
+ ironcurtain annotate-tools # classify MCP tool arguments (developer task)
160
+ ironcurtain compile-policy # compile constitution into enforceable rules (user task)
161
+ ```
162
+
163
+ Or with npm scripts during development: `npm run annotate-tools` / `npm run compile-policy`.
164
+
165
+ Tool annotation connects to your MCP servers and classifies each tool's arguments via LLM. This only needs re-running when you add or change MCP servers. Policy compilation translates your constitution into deterministic rules, generates test scenarios, and verifies them. The compiled artifacts are written to `src/config/generated/`. Review the generated `compiled-policy.json` -- these are the rules that will be enforced at runtime.
166
+
167
+ IronCurtain ships with pre-configured MCP servers for filesystem and git operations. See [Adding MCP Servers](#adding-mcp-servers) for how to extend this.
168
+
169
+ ### 4. Run the agent
170
+
171
+ **Interactive mode** (multi-turn session with human escalation support):
172
+
173
+ ```bash
174
+ ironcurtain start
175
+ ```
176
+
177
+ **Single-shot mode** (send one task, get a response):
178
+
179
+ ```bash
180
+ ironcurtain start "Summarize the files in the current directory"
181
+ ```
182
+
183
+ Or with npm scripts during development: `npm start` / `npm start "task"`.
184
+
185
+ ### Session Commands
186
+
187
+ During an interactive session:
188
+
189
+ | Command | Description |
190
+ |---------|-------------|
191
+ | `/approve` | Approve a pending escalation request |
192
+ | `/deny` | Deny a pending escalation request |
193
+ | `/budget` | Show resource consumption (tokens, steps, cost) |
194
+ | `/logs` | Display diagnostic events |
195
+ | `/quit` | End the session |
196
+
197
+ ## Configuration
198
+
199
+ IronCurtain stores its configuration and session data in `~/.ironcurtain/`:
200
+
201
+ ```
202
+ ~/.ironcurtain/
203
+ ├── config.json # User configuration
204
+ ├── sessions/
205
+ │ └── {sessionId}/
206
+ │ ├── sandbox/ # Per-session filesystem sandbox
207
+ │ ├── escalations/ # File-based IPC for human approval
208
+ │ ├── audit.jsonl # Per-session audit log
209
+ │ └── session.log # Diagnostics
210
+ ```
211
+
212
+ ### Resource Budgets
213
+
214
+ Sessions enforce configurable limits to prevent runaway agents:
215
+
216
+ | Limit | Default | Config Key |
217
+ |-------|---------|------------|
218
+ | Max tokens | 1,000,000 | `resourceBudget.maxTotalTokens` |
219
+ | Max steps | 200 | `resourceBudget.maxSteps` |
220
+ | Session timeout | 30 minutes | `resourceBudget.maxSessionSeconds` |
221
+ | Cost cap | $5.00 | `resourceBudget.maxEstimatedCostUsd` |
222
+
223
+ Set any limit to `null` in `config.json` to disable it.
224
+
225
+ ### Multi-Provider Support
226
+
227
+ IronCurtain supports multiple LLM providers. Use the `provider:model-name` format in config and provide the API key for each provider you use:
228
+
229
+ ```json
230
+ {
231
+ "agentModelId": "anthropic:claude-sonnet-4-6",
232
+ "policyModelId": "google:gemini-2.5-flash",
233
+ "googleApiKey": "AIza..."
234
+ }
235
+ ```
236
+
237
+ Each provider has its own API key field in the config (and corresponding environment variable):
238
+
239
+ | Provider | Config Key | Environment Variable |
240
+ |----------|-----------|---------------------|
241
+ | Anthropic | `anthropicApiKey` | `ANTHROPIC_API_KEY` |
242
+ | Google | `googleApiKey` | `GOOGLE_GENERATIVE_AI_API_KEY` |
243
+ | OpenAI | `openaiApiKey` | `OPENAI_API_KEY` |
244
+
245
+ Environment variables take precedence over config file values.
246
+
247
+ ### Adding MCP Servers
248
+
249
+ IronCurtain ships with filesystem and git MCP servers pre-configured. Adding a new server is a developer-level task that may involve changes across several files:
250
+
251
+ 1. **Register the server** in `src/config/mcp-servers.json` with its command, arguments, and optional environment variables or sandbox settings.
252
+ 2. **Extend the argument role registry** in `src/types/argument-roles.ts` if the new server's tools have argument semantics not covered by existing roles (e.g., `read-path`, `write-path`, `fetch-url`). Each role defines how values are normalized and evaluated by the policy engine.
253
+ 3. **Update the constitution** in `src/config/constitution.md` to cover the new server's capabilities.
254
+ 4. **Re-run `ironcurtain annotate-tools`** (or `npm run annotate-tools`) to classify the new server's tool arguments by role.
255
+ 5. **Re-run `ironcurtain compile-policy`** (or `npm run compile-policy`) to compile policy rules from your constitution. The verification stage will flag gaps.
256
+
257
+ After compilation, review the updated `tool-annotations.json` and `compiled-policy.json` to verify the new tools are correctly classified and covered by policy.
258
+
259
+ ## Security Model
260
+
261
+ IronCurtain is designed around a specific threat model: **the LLM goes rogue.** This can happen through prompt injection (a malicious email or web page hijacks the agent) or through multi-turn drift (the agent gradually deviates from the user's intent over a long session).
262
+
263
+ ### What IronCurtain enforces
264
+
265
+ - **Filesystem containment** -- Path-based policy with symlink-aware resolution prevents path traversal and symlink-escape attacks.
266
+ - **Per-tool policy** -- Each MCP tool call is evaluated against compiled rules. The policy engine classifies tool arguments by role (read-path, write-path, delete-path) to make fine-grained decisions.
267
+ - **Structural invariants** -- Certain protections are hardcoded and cannot be overridden by the constitution: the agent can never modify its own policy files, audit logs, or configuration.
268
+ - **Human escalation** -- When policy says "escalate," the agent pauses and the user must explicitly `/approve` or `/deny` the action.
269
+ - **Audit trail** -- Every tool call and policy decision is logged to an append-only JSONL audit log.
270
+ - **Resource limits** -- Token, step, time, and cost budgets prevent runaway sessions.
271
+
272
+ ### Known limitations
273
+
274
+ This is a research prototype. Known gaps include:
275
+
276
+ - **Policy compilation fidelity** -- The LLM-based compiler can misinterpret constitution intent. The verification pipeline catches many errors but is not exhaustive. Always review the compiled `compiled-policy.json`.
277
+ - **V8 isolate boundaries** -- The sandbox uses V8 isolates, not OS-level virtualization. A V8 zero-day could allow escape (though the agent has no knowledge of how to exploit one).
278
+ - **No outbound content inspection** -- An agent allowed to write files could encode sensitive data to bypass content-level controls. Planned: LLM-based intelligibility checks on outbound content.
279
+ - **Escalation fatigue** -- Too many false-positive escalations can lead to habitual approval. Tune your constitution to minimize unnecessary prompts.
280
+
281
+ See [docs/SECURITY_CONCERNS.md](docs/SECURITY_CONCERNS.md) for a detailed threat analysis.
282
+
283
+ ## Development
284
+
285
+ ```bash
286
+ npm test # Run all tests
287
+ npx vitest run test/policy-engine.test.ts # Run a single test file
288
+ npx vitest run -t "denies delete_file" # Run a single test by name
289
+ npm run lint # Lint
290
+ npm run build # TypeScript compilation + asset copy
291
+ ```
292
+
293
+ ### Project Structure
294
+
295
+ ```
296
+ src/
297
+ ├── index.ts # Entry point
298
+ ├── config/ # Configuration loading, constitution, MCP server definitions
299
+ │ ├── constitution.md # Your security policy in plain English
300
+ │ ├── mcp-servers.json # MCP server definitions
301
+ │ └── generated/ # Compiled policy artifacts (do not edit manually)
302
+ ├── session/ # Multi-turn session management, budgets, loop detection
303
+ ├── sandbox/ # V8 isolated execution environment
304
+ ├── trusted-process/ # Policy engine, MCP proxy, audit log, escalation
305
+ ├── pipeline/ # Constitution → policy compilation pipeline
306
+ └── types/ # Shared type definitions
307
+ ```
308
+
309
+ ## License
310
+
311
+ [Apache-2.0](LICENSE)
@@ -0,0 +1,10 @@
1
+ import type { Sandbox } from '../sandbox/index.js';
2
+ /**
3
+ * Runs the agent for a single task. This is the legacy single-shot entry point.
4
+ *
5
+ * @deprecated Use {@link createSession} from `src/session/index.ts` instead.
6
+ * Sessions provide multi-turn conversation, per-session isolation, and
7
+ * escalation routing. This function is retained for backward compatibility
8
+ * with integration tests but should not be used in new code.
9
+ */
10
+ export declare function runAgent(task: string, sandbox: Sandbox): Promise<string>;
@@ -0,0 +1,71 @@
1
+ import { generateText, tool, stepCountIs } from 'ai';
2
+ import { anthropic } from '@ai-sdk/anthropic';
3
+ import { z } from 'zod';
4
+ import { buildSystemPrompt } from './prompts.js';
5
+ import * as logger from '../logger.js';
6
+ const MAX_AGENT_STEPS = 10;
7
+ /**
8
+ * Runs the agent for a single task. This is the legacy single-shot entry point.
9
+ *
10
+ * @deprecated Use {@link createSession} from `src/session/index.ts` instead.
11
+ * Sessions provide multi-turn conversation, per-session isolation, and
12
+ * escalation routing. This function is retained for backward compatibility
13
+ * with integration tests but should not be used in new code.
14
+ */
15
+ export async function runAgent(task, sandbox) {
16
+ const toolInterfaces = sandbox.getToolInterfaces();
17
+ const tools = {
18
+ execute_code: tool({
19
+ description: 'Execute TypeScript code in a secure sandbox with access to filesystem tools. ' +
20
+ 'Write code that calls tool functions like filesystem.filesystem_read_file({ path }), ' +
21
+ 'filesystem.filesystem_list_directory({ path }), etc. ' +
22
+ 'Tools are synchronous — no await needed. Use return to provide results. ' +
23
+ 'Call __getToolInterface(\'tool.name\') to discover the full type signature of any tool.',
24
+ inputSchema: z.object({
25
+ code: z.string().describe('TypeScript code to execute in the sandbox'),
26
+ }),
27
+ execute: async ({ code }) => {
28
+ logger.info(`[sandbox] Executing code (${code.length} chars)`);
29
+ try {
30
+ const { result, logs } = await sandbox.executeCode(code);
31
+ const output = {};
32
+ if (logs.length > 0) {
33
+ output.console = logs;
34
+ }
35
+ output.result = result;
36
+ return output;
37
+ }
38
+ catch (err) {
39
+ return {
40
+ error: err instanceof Error ? err.message : String(err),
41
+ };
42
+ }
43
+ },
44
+ }),
45
+ };
46
+ logger.info(`Agent starting with Code Mode sandbox`);
47
+ logger.info(`Task: ${task}`);
48
+ const result = await generateText({
49
+ model: anthropic('claude-sonnet-4-6'),
50
+ system: buildSystemPrompt(toolInterfaces),
51
+ prompt: task,
52
+ tools,
53
+ stopWhen: stepCountIs(MAX_AGENT_STEPS),
54
+ onStepFinish({ text, toolCalls }) {
55
+ if (toolCalls && toolCalls.length > 0) {
56
+ for (const tc of toolCalls) {
57
+ if (tc.toolName === 'execute_code' && 'input' in tc) {
58
+ const input = tc.input;
59
+ const preview = input.code.substring(0, 120).replace(/\n/g, '\\n');
60
+ logger.info(`Tool: execute_code("${preview}${input.code.length > 120 ? '...' : ''}")`);
61
+ }
62
+ }
63
+ }
64
+ if (text) {
65
+ logger.info(`Agent: ${text.substring(0, 200)}${text.length > 200 ? '...' : ''}`);
66
+ }
67
+ },
68
+ });
69
+ return result.text;
70
+ }
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Builds the system prompt for the agent. Shared between
3
+ * the legacy runAgent() function and the new AgentSession.
4
+ */
5
+ export declare function buildSystemPrompt(toolCatalog: string, allowedDirectory?: string): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Builds the system prompt for the agent. Shared between
3
+ * the legacy runAgent() function and the new AgentSession.
4
+ */
5
+ export function buildSystemPrompt(toolCatalog, allowedDirectory) {
6
+ const sandboxInfo = allowedDirectory
7
+ ? `\nYour sandbox directory is: ${allowedDirectory}\nAll file operations within this directory are automatically allowed.\n`
8
+ : '';
9
+ return `You are a helpful assistant. You complete tasks by writing TypeScript code that executes in a secure sandbox.
10
+
11
+ Every tool call in your code goes through a security policy engine. If a call is denied, do NOT retry it -- explain the denial to the user.
12
+ ${sandboxInfo}
13
+ ## Code Mode rules
14
+
15
+ - Tools are synchronous — do NOT use \`await\`.
16
+ - Use \`return\` to send a value back to the conversation.
17
+ - Example: \`const result = filesystem.filesystem_list_directory({ path: "/tmp" });\`
18
+
19
+ ## Available tools
20
+
21
+ ${toolCatalog}
22
+
23
+ To get the full TypeScript interface for any tool (parameter types, optional params), call \`__getToolInterface('tool.name')\` inside your code.
24
+ `;
25
+ }
26
+ //# sourceMappingURL=prompts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../../src/agent/prompts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAC/B,WAAmB,EACnB,gBAAyB;IAEzB,MAAM,WAAW,GAAG,gBAAgB;QAClC,CAAC,CAAC,gCAAgC,gBAAgB,0EAA0E;QAC5H,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO;;;EAGP,WAAW;;;;;;;;;EASX,WAAW;;;CAGZ,CAAC;AACF,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { type ToolSet } from 'ai';
2
+ import type { TrustedProcess } from '../trusted-process/index.js';
3
+ /**
4
+ * Creates AI SDK tools from MCP tool schemas for direct tool-call mode.
5
+ * Each tool's execute function routes through the trusted process,
6
+ * which evaluates policy before forwarding to the real MCP server.
7
+ * Used for testing and as a fallback; the primary mode is Code Mode.
8
+ */
9
+ export declare function createToolsFromMCPServer(serverName: string, mcpTools: {
10
+ name: string;
11
+ description?: string;
12
+ inputSchema: unknown;
13
+ }[], trustedProcess: TrustedProcess): ToolSet;