harnis 1.0.0__tar.gz

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 (76) hide show
  1. harnis-1.0.0/LICENSE +202 -0
  2. harnis-1.0.0/NOTICE +10 -0
  3. harnis-1.0.0/PKG-INFO +402 -0
  4. harnis-1.0.0/README.md +344 -0
  5. harnis-1.0.0/harnis/__init__.py +9 -0
  6. harnis-1.0.0/harnis/alerts.py +69 -0
  7. harnis-1.0.0/harnis/api.py +650 -0
  8. harnis-1.0.0/harnis/auth.py +313 -0
  9. harnis-1.0.0/harnis/backup.py +175 -0
  10. harnis-1.0.0/harnis/cache.py +206 -0
  11. harnis-1.0.0/harnis/cli.py +164 -0
  12. harnis-1.0.0/harnis/config.py +250 -0
  13. harnis-1.0.0/harnis/db.py +54 -0
  14. harnis-1.0.0/harnis/egress_proxy.py +221 -0
  15. harnis-1.0.0/harnis/evals.py +603 -0
  16. harnis-1.0.0/harnis/guardrails.py +153 -0
  17. harnis-1.0.0/harnis/infra.py +89 -0
  18. harnis-1.0.0/harnis/k8s_sandbox.py +726 -0
  19. harnis-1.0.0/harnis/llm/__init__.py +7 -0
  20. harnis-1.0.0/harnis/llm/pricing.py +119 -0
  21. harnis-1.0.0/harnis/llm/providers.py +505 -0
  22. harnis-1.0.0/harnis/llm/router.py +194 -0
  23. harnis-1.0.0/harnis/llm/types.py +109 -0
  24. harnis-1.0.0/harnis/maintenance.py +85 -0
  25. harnis-1.0.0/harnis/metrics.py +65 -0
  26. harnis-1.0.0/harnis/migrate.py +104 -0
  27. harnis-1.0.0/harnis/migrations/001_schema.sql +213 -0
  28. harnis-1.0.0/harnis/migrations/002_grants.sql +21 -0
  29. harnis-1.0.0/harnis/migrations/003_more_providers.sql +19 -0
  30. harnis-1.0.0/harnis/migrations/004_admin_and_api_keys.sql +119 -0
  31. harnis-1.0.0/harnis/migrations/005_provider_wildcard.sql +36 -0
  32. harnis-1.0.0/harnis/migrations/006_data_lifecycle.sql +194 -0
  33. harnis-1.0.0/harnis/migrations/__init__.py +2 -0
  34. harnis-1.0.0/harnis/orchestrator.py +519 -0
  35. harnis-1.0.0/harnis/plugins.py +267 -0
  36. harnis-1.0.0/harnis/sandbox.py +557 -0
  37. harnis-1.0.0/harnis/static/console.css +229 -0
  38. harnis-1.0.0/harnis/static/console.js +957 -0
  39. harnis-1.0.0/harnis/static/favicon.svg +1 -0
  40. harnis-1.0.0/harnis/static/index.html +19 -0
  41. harnis-1.0.0/harnis/store.py +319 -0
  42. harnis-1.0.0/harnis/telemetry.py +163 -0
  43. harnis-1.0.0/harnis/tools.py +397 -0
  44. harnis-1.0.0/harnis.egg-info/PKG-INFO +402 -0
  45. harnis-1.0.0/harnis.egg-info/SOURCES.txt +74 -0
  46. harnis-1.0.0/harnis.egg-info/dependency_links.txt +1 -0
  47. harnis-1.0.0/harnis.egg-info/entry_points.txt +2 -0
  48. harnis-1.0.0/harnis.egg-info/requires.txt +31 -0
  49. harnis-1.0.0/harnis.egg-info/top_level.txt +1 -0
  50. harnis-1.0.0/pyproject.toml +82 -0
  51. harnis-1.0.0/setup.cfg +4 -0
  52. harnis-1.0.0/tests/test_admin_api.py +201 -0
  53. harnis-1.0.0/tests/test_api_e2e.py +192 -0
  54. harnis-1.0.0/tests/test_auth_oidc.py +179 -0
  55. harnis-1.0.0/tests/test_backup.py +74 -0
  56. harnis-1.0.0/tests/test_cache_resp3.py +128 -0
  57. harnis-1.0.0/tests/test_check_script.py +52 -0
  58. harnis-1.0.0/tests/test_components.py +196 -0
  59. harnis-1.0.0/tests/test_console.py +368 -0
  60. harnis-1.0.0/tests/test_console_config.py +78 -0
  61. harnis-1.0.0/tests/test_egress.py +378 -0
  62. harnis-1.0.0/tests/test_evals.py +118 -0
  63. harnis-1.0.0/tests/test_guardrails.py +71 -0
  64. harnis-1.0.0/tests/test_k8s_sandbox.py +688 -0
  65. harnis-1.0.0/tests/test_keycloak.py +182 -0
  66. harnis-1.0.0/tests/test_lifecycle.py +148 -0
  67. harnis-1.0.0/tests/test_metrics.py +67 -0
  68. harnis-1.0.0/tests/test_orchestrator.py +316 -0
  69. harnis-1.0.0/tests/test_plugins.py +195 -0
  70. harnis-1.0.0/tests/test_pricing.py +120 -0
  71. harnis-1.0.0/tests/test_provider_adapters.py +374 -0
  72. harnis-1.0.0/tests/test_rls.py +158 -0
  73. harnis-1.0.0/tests/test_router.py +125 -0
  74. harnis-1.0.0/tests/test_sandbox.py +150 -0
  75. harnis-1.0.0/tests/test_sandbox_archive.py +80 -0
  76. harnis-1.0.0/tests/test_upgrade.py +61 -0
harnis-1.0.0/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 [yyyy] [name of copyright owner]
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.
harnis-1.0.0/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ Harnis
2
+ Copyright 2026 Ahmad Karawash
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE)
5
+ and is provided "AS IS", WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
6
+
7
+ This distribution contains no third-party code. Dependencies, container base
8
+ images, models and services used with Harnis are provided by third parties
9
+ under their own licenses and terms; users are responsible for reviewing them
10
+ and obtaining any licenses they need.
harnis-1.0.0/PKG-INFO ADDED
@@ -0,0 +1,402 @@
1
+ Metadata-Version: 2.4
2
+ Name: harnis
3
+ Version: 1.0.0
4
+ Summary: Harnis: an open-source, multi-tenant agent harness for companies: coding agents, multi-agent workflows and stateful apps with approvals, sandboxing and tenant isolation.
5
+ Author: Ahmad Karawash
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/karawash-projects/harnis
8
+ Project-URL: Documentation, https://github.com/karawash-projects/harnis#readme
9
+ Project-URL: Issues, https://github.com/karawash-projects/harnis/issues
10
+ Project-URL: Changelog, https://github.com/karawash-projects/harnis/blob/main/CHANGELOG.md
11
+ Keywords: ai-agents,llm,agent-harness,multi-tenant,sandbox,human-in-the-loop,fastapi,anthropic,openai,gemini,bedrock
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Framework :: FastAPI
22
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
23
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
24
+ Requires-Python: >=3.11
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ License-File: NOTICE
28
+ Requires-Dist: prometheus-client>=0.20
29
+ Requires-Dist: fastapi>=0.115
30
+ Requires-Dist: uvicorn[standard]>=0.30
31
+ Requires-Dist: pydantic>=2.7
32
+ Requires-Dist: pydantic-settings>=2.3
33
+ Requires-Dist: psycopg[binary,pool]>=3.2
34
+ Requires-Dist: redis>=5.0
35
+ Requires-Dist: numpy>=1.26
36
+ Requires-Dist: httpx>=0.27
37
+ Requires-Dist: PyJWT[crypto]>=2.8
38
+ Requires-Dist: docker>=7.0
39
+ Requires-Dist: anthropic>=0.40
40
+ Requires-Dist: openai>=1.50
41
+ Requires-Dist: google-genai>=1.50
42
+ Requires-Dist: boto3>=1.35
43
+ Requires-Dist: PyYAML>=6.0
44
+ Requires-Dist: opentelemetry-api>=1.27
45
+ Requires-Dist: opentelemetry-sdk>=1.27
46
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc>=1.27
47
+ Requires-Dist: opentelemetry-instrumentation-fastapi>=0.48b0
48
+ Requires-Dist: opentelemetry-instrumentation-psycopg>=0.48b0
49
+ Requires-Dist: opentelemetry-instrumentation-redis>=0.48b0
50
+ Provides-Extra: k8s
51
+ Requires-Dist: kubernetes>=31; extra == "k8s"
52
+ Provides-Extra: dev
53
+ Requires-Dist: pytest>=8; extra == "dev"
54
+ Requires-Dist: fakeredis[lua]>=2.23; extra == "dev"
55
+ Requires-Dist: kubernetes>=31; extra == "dev"
56
+ Requires-Dist: build>=1.2; extra == "dev"
57
+ Dynamic: license-file
58
+
59
+ # Harnis
60
+
61
+ **An open-source, self-hosted platform for running AI agents safely inside a company.**
62
+
63
+ Harnis gives your teams one place to run agents that read and change real things (code, files, tickets, internal systems) without handing a model the keys. Every agent runs inside the same harness: tenant isolation enforced by the database, side effects held for human approval, untrusted code in a locked-down sandbox, budgets and loop breakers on every turn, and a full audit trail.
64
+
65
+ It ships with three workloads on one engine:
66
+
67
+ * a **CLI coding agent** that edits your project only after you approve each change,
68
+ * a **multi-agent workflow** (a router hands messages to specialist agents, which can hand off to each other),
69
+ * a **multi-tenant web app** with streaming events and an approval console.
70
+
71
+ Bring your own models (Anthropic, OpenAI, Google Gemini, Amazon Nova on Bedrock, or anything with an OpenAI-compatible API, such as vLLM or Ollama), your own identity provider (any OIDC IdP), and your own tools and agents (plugins). Run it with Docker Compose on a laptop or with the Helm chart on Kubernetes.
72
+
73
+ Licensed under [Apache 2.0](LICENSE) and provided **as is**, without warranty or support: you are free to use, change and extend it, and you are responsible for how you run it (see [Use at your own risk](#use-at-your-own-risk)).
74
+
75
+ ## Why Harnis
76
+
77
+ | You need | Harnis gives you |
78
+ |---|---|
79
+ | Agents that can't leak one customer's data to another | Postgres row-level security, **enabled and forced**, on every tenant table; the app connects as a non-owner role and sets the tenant per transaction from the verified token |
80
+ | A human in the loop for anything that matters | High-risk tool calls suspend the session in the database; the approval is bound to a SHA-256 of the exact action, with separation of duties and expiry |
81
+ | Model-written code that can't escape | One throwaway container (Docker) or Pod (Kubernetes) per command: no network, read-only root, all capabilities dropped, non-root, memory/CPU/PID limits; gVisor supported |
82
+ | Control over where data goes | Per-tenant provider allow-lists; failover never leaves them |
83
+ | Your SSO, your roles | OIDC with JWKS discovery and rotation, claim and group mapping; service API keys for automation |
84
+ | Your own tools and agents | A plugin SDK: tools, agents and model providers register exactly like the built-ins |
85
+ | Predictable cost | Per-turn budgets for steps, USD cost, hand-offs and tool calls; per-tenant cost caps; a token and cost ledger |
86
+ | Evidence for auditors | Append-only audit log with JSON / NDJSON export, OpenTelemetry traces, alerts |
87
+
88
+ ## Architecture
89
+
90
+ ```
91
+ +--------------------------- API replica (stateless) ----------------------------+
92
+ browser / CLI ---> | auth --> rate limit --> session lock --> Orchestrator (checkpointed state machine) |
93
+ OIDC token or | | |
94
+ hrn_ API key | ingest -> route -> [cache] -> agent <-> tools -> respond |
95
+ | guardrails fast model tenant- LLM router low risk: run (sandbox if code) |
96
+ | scoped (failover) high risk: SUSPEND for a human |
97
+ | plugins: tools, agents, providers |
98
+ +------+----------------+---------------+-------------------------+---------------+
99
+ | | | |
100
+ Postgres (RLS) Redis Anthropic, OpenAI, Sandbox
101
+ sessions, approvals, rate limits, Gemini, Nova (Bedrock), Docker container or
102
+ prompts, API keys, locks, events, OpenAI-compatible, Kubernetes Pod per
103
+ ledger, audit, circuit your own (plugin), command: no network,
104
+ analytics breaker, cache (+ offline mock) read-only, non-root
105
+ ```
106
+
107
+ Session state lives in Postgres and Redis, so a session suspended for approval on one replica resumes on whichever replica receives the decision. Session files live in the workspaces directory, which must be shared storage when you run more than one replica; see [Scaling](docs/kubernetes.md#scaling). See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for the full design.
108
+
109
+ ## Quick start (about 5 minutes, no API keys needed)
110
+
111
+ Works the same on **Windows, macOS and Linux**. You need Python 3.11 or newer and Docker (Docker Desktop on Windows and macOS, Docker Engine on Linux).
112
+
113
+ Every step goes through `tasks.py`, a standard-library task runner, so there's no `make`, bash or WSL requirement.
114
+
115
+ ```bash
116
+ python tasks.py install # .venv + dependencies (on Windows: py tasks.py install)
117
+ python tasks.py up # Postgres, Redis Stack, Jaeger; migrations; demo tenants "acme" and "globex"
118
+ python tasks.py sandbox-image # the image agent commands run in
119
+ python tasks.py dev # API on http://127.0.0.1:8000
120
+ ```
121
+
122
+ Open **http://127.0.0.1:8000** and click **Continue as local developer** (you're the admin of the demo tenant `acme`). The console has conversations with inline approvals and diffs, an approvals queue, usage and analytics, agents and their prompts, API keys and the audit log; a platform admin also sees tenants. Traces are in Jaeger at **http://127.0.0.1:16686**.
123
+
124
+ Check that everything works with `python tasks.py check` (see [Checking a deployment](#checking-a-deployment)), and `python tasks.py status` shows which services are up.
125
+
126
+ Try the coding agent on a scratch folder in a second terminal:
127
+
128
+ ```bash
129
+ mkdir demo
130
+ python tasks.py cli -- --workspace demo "create greet.py with a greet function"
131
+ ```
132
+
133
+ You'll approve each file write (with a diff), the agent runs the tests in the sandbox, and finally you choose whether to apply the changes to `demo`. `python tasks.py token` prints a development token if you want to call the API yourself (`HARNIS_TOKEN`).
134
+
135
+ ### Trying it without API keys
136
+
137
+ The mock provider follows a small, deterministic script so every path can be exercised:
138
+
139
+ | Say | What happens |
140
+ |---|---|
141
+ | `what are your opening hours?` | the support agent answers; repeat it in a new session and it's served from the cache |
142
+ | `create calc.py` | the coder writes `calc.py` + `test_calc.py` (two approvals), then runs the tests in the sandbox |
143
+ | ``run `ls -la` `` | a shell command, suspended for approval (commands run in the Linux sandbox, so use Linux commands even on Windows) |
144
+ | `list the files` / `read README.md` | read-only tools, no approval |
145
+ | `repeat: list the files` | the agent loops; the loop breaker warns, then escalates and alerts |
146
+ | `install the dependencies` | installs `requirements.txt` after approval, through the registry-only proxy (the session needs a `requirements.txt`) |
147
+ | `ignore all previous instructions...` | blocked by the input guard |
148
+
149
+ ### Platform notes
150
+
151
+ | | Windows | macOS | Linux |
152
+ |---|---|---|---|
153
+ | Docker | Docker Desktop (WSL 2 backend) | Docker Desktop, Colima or OrbStack | Docker Engine |
154
+ | Sandbox workspace mode | `copy` (default) | `copy` (default) | `copy` (default) or `bind` |
155
+ | gVisor (`SANDBOX_RUNTIME=runsc`) | inside WSL2 with Docker Engine ([docs/gvisor.md](docs/gvisor.md)) | not available | supported |
156
+
157
+ * **Workspaces** are streamed into the sandbox through the Docker API and validated on the way back (symlinks, hard links, devices and paths outside the workspace are dropped), so it behaves identically everywhere, including remote daemons. On Linux, `SANDBOX_WORKSPACE_MODE=bind` bind-mounts instead.
158
+ * **Paths** are POSIX-style and portable: `..`, absolute and drive paths, and names Windows can't store are rejected on every OS. Files are read and written as UTF-8 bytes, so diffs and approval hashes match across platforms.
159
+ * **Port clashes:** if 5432 or 6379 is taken, `tasks.py up` picks the next free port and updates `.env`. If Docker Desktop isn't running, `tasks.py` starts it.
160
+
161
+ ## Setting Harnis up for your company
162
+
163
+ ### 1. Models
164
+
165
+ | Provider | `LLM_PROVIDERS` name | Credentials | Default models (main / fast) |
166
+ |---|---|---|---|
167
+ | Anthropic | `anthropic` | `ANTHROPIC_API_KEY` | `claude-sonnet-5-5` / `claude-haiku-5-5` |
168
+ | OpenAI | `openai` | `OPENAI_API_KEY` | `gpt-5.5` / `gpt-5.4-mini` |
169
+ | Google Gemini | `gemini` | `GEMINI_API_KEY`, or Vertex AI with `GEMINI_USE_VERTEXAI=true` | `gemini-3.8-flash` / `gemini-3.5-flash-lite` |
170
+ | Amazon Nova (Bedrock) | `nova` | `AWS_REGION` plus AWS credentials (keys, `AWS_PROFILE`/SSO, or an IAM role) | `us.amazon.nova-2-lite-v1:0` / `us.amazon.nova-micro-v1:0` |
171
+ | Self-hosted / gateway | `openai_compatible` | `OPENAI_COMPATIBLE_BASE_URL`, `OPENAI_COMPATIBLE_MODEL` (vLLM, Ollama, LM Studio, LiteLLM) | yours |
172
+ | Your own | plugin | see [docs/plugins.md](docs/plugins.md) | yours |
173
+
174
+ `LLM_PROVIDERS` is the failover order. Providers without credentials are skipped and the API logs the resulting chain at startup; `mock` is refused when `ENV=production`. Model names change often, so set `*_MODEL` / `*_FAST_MODEL` to what your account offers.
175
+
176
+ **Model prices.** Cost figures, per-turn cost budgets and tenant cost caps depend on each model's price, and prices change. `python tasks.py pricing` asks for the price of every model you have configured (showing reference values to check against the provider's pricing page) and saves them as `PRICING_OVERRIDES`; `tasks.py dev` asks too when some are missing. With `ENV=production` the API refuses to start while a configured model has no confirmed price. Admins see the prices and their status under **Usage & analytics** in the console (`GET /v1/admin/pricing`).
177
+
178
+ ### 2. Single sign-on (OIDC)
179
+
180
+ Set `AUTH_MODE=oidc` and point Harnis at your IdP (Okta, Microsoft Entra ID, Auth0, Keycloak, Google, ...):
181
+
182
+ ```bash
183
+ AUTH_MODE=oidc
184
+ OIDC_ISSUER=https://login.example.com/
185
+ OIDC_AUDIENCE=harnis-api
186
+ OIDC_TENANT_CLAIM=tenant_id # or OIDC_DEFAULT_TENANT=acme for a single-tenant deployment
187
+ OIDC_ROLES_CLAIM=groups # realm_access.roles for Keycloak; dotted paths work
188
+ OIDC_ROLE_MAP={"harnis-reviewers": "reviewer", "harnis-admins": "admin", "platform-ops": "platform-admin"}
189
+ ```
190
+
191
+ Keys are discovered from the issuer and refreshed on rotation; only asymmetric algorithms are accepted. The tenant always comes from the verified token, never from the request.
192
+
193
+ **Console sign-in.** Register a public single-page-app client in your IdP with the redirect URI `https://<your-harnis-host>/`, and set its client id. The console then shows **Sign in with SSO** and uses the authorization code flow with PKCE; no client secret is involved and the dev-token button disappears.
194
+
195
+ ```bash
196
+ OIDC_CONSOLE_CLIENT_ID=0oa1b2c3d4
197
+ OIDC_CONSOLE_SCOPES=openid profile email # add your API scope if the IdP needs one (Entra ID: api://harnis/access)
198
+ OIDC_CONSOLE_EXTRA_PARAMS={"audience": "harnis-api"} # Auth0 needs this to issue an access token for the API
199
+ # OIDC_CONSOLE_TOKEN=id_token # if your IdP's access tokens aren't JWTs for OIDC_AUDIENCE
200
+ ```
201
+
202
+ The console keeps the token in the browser tab's session storage (gone when the tab closes), signs out when it expires, and is served with a strict Content-Security-Policy. Set `CONSOLE_ENABLED=false` to serve only the API.
203
+
204
+ | Role | Can |
205
+ |---|---|
206
+ | `user` | create sessions and talk to agents |
207
+ | `reviewer` | see the tenant's sessions, approve or deny actions, view analytics |
208
+ | `admin` | everything a reviewer can, plus prompts, API keys and the tenant's audit log |
209
+ | `platform-admin` | create, configure and disable tenants (no access to tenant data) |
210
+
211
+ **Try SSO locally with Keycloak.** One command starts a Keycloak with a ready `harnis` realm (test users for every role, two tenants) and switches `.env` to `AUTH_MODE=oidc` against it:
212
+
213
+ ```bash
214
+ python tasks.py sso-up # then restart `python tasks.py dev` and click "Sign in with SSO" (adam / harnis-local-only)
215
+ python tasks.py sso-check # feature check with Keycloak-issued tokens
216
+ python tasks.py sso-down # back to local auth
217
+ ```
218
+
219
+ The test users, passwords and password-grant client are for local testing only. See [docs/keycloak.md](docs/keycloak.md), which also shows how the realm maps to the settings above so you can mirror it in your own IdP.
220
+
221
+ ### 3. Tenants
222
+
223
+ A `platform-admin` manages tenants through the API:
224
+
225
+ ```bash
226
+ curl -X PUT $HARNIS_API/v1/admin/tenants/acme -H "Authorization: Bearer $TOKEN" \
227
+ -H "Content-Type: application/json" \
228
+ -d '{"name": "Acme Corp", "allowed_providers": ["anthropic"], "max_cost_usd_per_turn": 1.0}'
229
+ ```
230
+
231
+ `allowed_providers` limits where the tenant's prompts may be sent (`["*"]`, the default, means every configured provider). Set `"active": false` to lock a tenant out immediately, including its API keys.
232
+
233
+ ### 4. Service API keys
234
+
235
+ Tenant admins create keys for CI jobs and integrations. The secret is shown once and stored only as a hash:
236
+
237
+ ```bash
238
+ curl -X POST $HARNIS_API/v1/admin/api-keys -H "Authorization: Bearer $TOKEN" \
239
+ -H "Content-Type: application/json" -d '{"name": "ci", "roles": ["user"], "expires_in_days": 90}'
240
+ # -> {"key": "hrn_...", ...} use it as: Authorization: Bearer hrn_...
241
+ ```
242
+
243
+ ### 5. Your own tools and agents
244
+
245
+ ```python
246
+ # mycompany_harnis.py
247
+ from pydantic import BaseModel
248
+ from harnis.plugins import AgentSpec
249
+ from harnis.tools import Tool
250
+
251
+ class Args(BaseModel):
252
+ order_id: str
253
+
254
+ def lookup(ctx, args):
255
+ return f"order {args.order_id}: shipped", False
256
+
257
+ def register(registry):
258
+ registry.add_tool(Tool("lookup_order", "Look up an order.", Args, "low", lookup))
259
+ registry.add_agent(AgentSpec(name="orders", description="questions about existing orders",
260
+ prompt="You answer questions about orders. Use lookup_order.",
261
+ tools=["lookup_order", "handoff", "escalate_to_human"]))
262
+ ```
263
+
264
+ Load it with `PLUGINS=mycompany_harnis`. Mark anything with side effects `risk="high"` and a reviewer approves each call. The [ticketing example](examples/plugins/harnis-plugin-tickets) is a complete, packaged plugin; [docs/plugins.md](docs/plugins.md) covers tools, agents, providers and testing.
265
+
266
+ ### 6. Kubernetes
267
+
268
+ ```bash
269
+ helm upgrade --install harnis ./deploy/helm/harnis --namespace harnis --create-namespace -f values-prod.yaml
270
+ ```
271
+
272
+ The chart runs the API as a Deployment (with optional HPA, PDB and Ingress), migrations as a pre-install/pre-upgrade Job, maintenance as a CronJob, and agent commands as one hardened Pod each in a separate namespace with Pod Security "restricted", a deny-all NetworkPolicy and optional gVisor. Database owner credentials live in a separate Secret that only the jobs can read.
273
+
274
+ Try it on your machine first with a local [kind](https://kind.sigs.k8s.io/) cluster: `python tasks.py k8s-up`, `python tasks.py k8s-check` (the full feature check against the cluster), `python tasks.py k8s-down`.
275
+
276
+ Read [docs/kubernetes.md](docs/kubernetes.md) before installing: it covers images, sandbox nodes, gVisor, Postgres and Redis, secrets, values and troubleshooting. The chart is linted, schema-validated and exercised on kind in CI, but has not been run on a production cluster, so test it in your own environment first. For running several API replicas, see [Scaling](docs/kubernetes.md#scaling).
277
+
278
+ ### 7. Operating it
279
+
280
+ [docs/operations.md](docs/operations.md) covers running Harnis in production: dependency installs and the egress proxy, model prices, data retention and user data requests (export and erasure), deleting tenants, backups and restore drills, upgrades, metrics and alerts, load testing, and a go-live checklist.
281
+
282
+ ## API
283
+
284
+ All endpoints except `/health`, `/ready` and `/` need `Authorization: Bearer <OIDC token, local JWT or hrn_ API key>`. Interactive docs are at `/docs`.
285
+
286
+ | Method & path | Role | Purpose |
287
+ |---|---|---|
288
+ | `POST /v1/sessions` | user | create a session, optional `{"files": {path: content}}` seed |
289
+ | `POST /v1/sessions/{id}/turns` | user (owner) | send a message; returns `completed`, `awaiting_approval`, `rejected`, `escalated` or `failed` |
290
+ | `GET /v1/sessions[/{id}]` | owner / reviewer | list or view sessions |
291
+ | `GET /v1/sessions/{id}/files` | owner / reviewer | the session workspace |
292
+ | `GET /v1/approvals` | reviewer | pending approvals with diff / command and `action_hash` |
293
+ | `POST /v1/approvals/{id}/decision` | reviewer (approve), requester or reviewer (deny) | `{"approved": bool, "action_hash": "..."}`; the session resumes in the background |
294
+ | `GET /v1/agents` | any | registered agents and their tools |
295
+ | `GET /v1/usage` | any | tokens and cost by model for your tenant |
296
+ | `GET /v1/analytics` | reviewer | hourly runs, latency, cache hit %, success % |
297
+ | `POST /v1/prompts`, `GET /v1/prompts/{key}` | admin | per-tenant prompt versions |
298
+ | `POST/GET /v1/admin/api-keys`, `DELETE /v1/admin/api-keys/{key_id}` | admin | service API keys |
299
+ | `GET /v1/admin/audit?after=&limit=&event_type=&format=ndjson` | admin | the tenant's audit log, paginated |
300
+ | `GET /v1/admin/pricing` | admin | model prices in use and whether the operator confirmed them |
301
+ | `GET /v1/admin/users/{id}/export` | admin | everything stored about one user of the tenant (right of access) |
302
+ | `DELETE /v1/admin/users/{id}/data?confirm={id}` | admin | erase a user's data; their id in retained history becomes a pseudonym |
303
+ | `GET /v1/admin/tenants`, `PUT /v1/admin/tenants/{id}` | platform-admin | tenant administration |
304
+ | `DELETE /v1/admin/tenants/{id}?confirm={id}` | platform-admin | delete a disabled tenant with all its data |
305
+ | `GET /v1/admin/platform-events` | platform-admin | platform audit trail (tenant deletions) |
306
+ | `GET /metrics` | scraper (`METRICS_TOKEN`) | Prometheus metrics |
307
+ | `GET /me` | any | who the token says you are |
308
+ | `WS /v1/ws?token=...` | any | live events (your sessions; plus approvals for reviewers) |
309
+
310
+ ## Checking a deployment
311
+
312
+ `scripts/harnis_check.py` is a standalone script (Python standard library only, no Harnis install needed) that exercises every feature against a running API and prints PASS / FAIL / SKIP for each: health and security headers, authentication and roles, API keys, conversations and routing, the semantic cache, approvals bound to the exact action, the sandbox (including that it has no network), guardrails, the loop breaker, separation of duties, tenant isolation, tenant administration, prompts, usage, the audit log, live events and rate limits.
313
+
314
+ ```bash
315
+ python tasks.py check # local: uses .env, tests in throwaway tenants
316
+ python scripts/harnis_check.py --api https://harnis.example.com \
317
+ --admin-token "$TENANT_ADMIN_TOKEN_OR_API_KEY" \
318
+ --platform-token "$PLATFORM_ADMIN_TOKEN" --other-admin-token "$ADMIN_OF_ANOTHER_TENANT" \
319
+ --report check.json # any deployment, including SSO
320
+ ```
321
+
322
+ With the JWT secret (local auth) it creates its own tenants and tests everything; with an admin token it runs inside that admin's tenant and skips what needs more credentials. Agent behaviour is checked exactly with the `mock` model; against a deployment without it, pass `--provider` (with a secret) and a smaller set of agent checks runs against the real model. It exits non-zero on any failure, so it can gate a deployment pipeline. Run `python scripts/harnis_check.py --help` for all options.
323
+
324
+ ## Testing gVisor and Kubernetes locally
325
+
326
+ * **gVisor** (kernel isolation for untrusted code): on Linux, or on Windows inside WSL2 with Docker Engine (Docker Desktop can't run `runsc`), install runsc and run `python tasks.py gvisor-check`. It verifies the runtime and runs the sandbox tests under gVisor. See [docs/gvisor.md](docs/gvisor.md). CI runs the same check on every push (`.github/workflows/gvisor.yml`).
327
+ * **Kubernetes**: with Docker Desktop (or Docker Engine), kind, kubectl and helm, run `python tasks.py k8s-up`, then `python tasks.py k8s-check`, then `python tasks.py k8s-down`. This deploys the Helm chart with throwaway Postgres/Redis and runs the full feature check, with sandbox commands running as Pods. See [docs/kubernetes.md](docs/kubernetes.md#try-it-locally-with-kind). CI runs it in `.github/workflows/k8s-e2e.yml`.
328
+
329
+ ## Tests and evals
330
+
331
+ ```bash
332
+ python tasks.py test unit # no services needed (runs on Windows, macOS and Linux CI)
333
+ python tasks.py test integration # RLS, auth and API end to end against real Postgres + Redis
334
+ python tasks.py test sandbox # container hardening against a real Docker daemon
335
+ python tasks.py test # everything
336
+ python tasks.py redteam # attack checks against a running API
337
+ python tasks.py test browser # the web console in Chromium, incl. SSO (pip install playwright; playwright install chromium)
338
+ python tasks.py eval -- --providers mock,anthropic,gemini,nova --repeat 3
339
+ ```
340
+
341
+ The eval suite (`evals/`) drives the live API like a user and a reviewer would, across support, coding, approvals, guardrails, multi-agent and robustness cases, and writes an HTML and JSON report. Each provider runs in its own tenant restricted to that provider, so results are comparable. Add cases for your own agents; see [evals/README.md](evals/README.md).
342
+
343
+ ## Security model: read before deploying
344
+
345
+ * **Prompt injection is not solved by the guardrail.** It catches common patterns. The containment is structural: least-privilege tools, a human for anything with side effects, commands in a sandbox without network, and budgets that stop runaway loops.
346
+ * **Containers are not a hard boundary** for hostile code: they share the kernel. Use gVisor (`SANDBOX_RUNTIME=runsc` with Docker, `sandbox.runtimeClassName` on Kubernetes), Kata or Firecracker for untrusted workloads.
347
+ * **Dependency installs are the one network path.** An approved `install_dependencies` run can reach only an allowlisting proxy, which tunnels HTTPS to the configured registries (PyPI and npm by default). Packages come from the internet: the reviewer approves the manifest, and npm lifecycle scripts are disabled, but a malicious package can still run code when the project's tests import it, inside the sandbox. Set `SANDBOX_INSTALL_ENABLED=false` or point `SANDBOX_EGRESS_ALLOW` at an internal mirror if that is not acceptable.
348
+ * **The Docker socket is root.** `python tasks.py up-full` mounts it into the API container for local convenience only. In production use the Kubernetes backend or a separate minimal runner.
349
+ * **Plugins run inside the API process** with its permissions. Install only plugins you trust and review them like your own code.
350
+ * **Never run the app as a Postgres superuser or table owner**; superusers bypass RLS even when it's forced. `harnis.migrate` creates the right roles.
351
+ * **Data leaving your boundary:** failover can send a tenant's prompts to another provider. Restrict it with `allowed_providers`, and check your privacy obligations (e.g. GDPR) before sending personal data to providers in other jurisdictions.
352
+ * With `AUTH_MODE=local`, use a long random `JWT_SECRET` and short-lived tokens. Don't log query strings (the WebSocket token travels there because browsers can't set headers on upgrades).
353
+
354
+ See [SECURITY.md](SECURITY.md) for the security model and how to share a vulnerability (there is no response commitment).
355
+
356
+ ## Project layout
357
+
358
+ ```
359
+ tasks.py cross-platform task runner (install, up, dev, test, cli, eval, ...)
360
+ harnis/
361
+ api.py FastAPI app, routes, admin API, WebSocket
362
+ auth.py local JWT, OIDC, API keys, roles
363
+ orchestrator.py state machine, budgets, loop breaker, approvals
364
+ plugins.py registry and plugin SDK (built-in agents and providers register here too)
365
+ tools.py built-in tools, risk tiers, workspace confinement
366
+ sandbox.py hardened Docker runner
367
+ k8s_sandbox.py hardened Kubernetes Pod runner
368
+ guardrails.py input / output / tool-output filters
369
+ llm/ neutral types, providers, router, pricing
370
+ cache.py tenant-scoped semantic cache
371
+ store.py, db.py Postgres access (RLS)
372
+ infra.py rate limits, locks, event bus
373
+ egress_proxy.py allowlisting HTTPS proxy for dependency installs
374
+ metrics.py Prometheus metrics
375
+ backup.py backup, verify, restore
376
+ telemetry.py, alerts.py, config.py, migrate.py, maintenance.py, cli.py, evals.py
377
+ migrations/ SQL
378
+ static/ web console
379
+ deploy/helm/harnis/ Helm chart
380
+ deploy/keycloak/ local Keycloak realm (testing only)
381
+ deploy/local-k8s/ kind cluster, throwaway Postgres/Redis, chart values
382
+ docs/ architecture, operations, Kubernetes, gVisor, Keycloak, plugins
383
+ scripts/ harnis_check.py (feature check), load_test.py, keycloak_local.py, k8s_local.py, gvisor_check.py
384
+ examples/plugins/ a complete example plugin
385
+ tests/ redteam/ evals/
386
+ ```
387
+
388
+ ## Contributing
389
+
390
+ Contributions are welcome (bug reports, docs, plugins, providers and fixes), with no commitment to review or merge them. Read [CONTRIBUTING.md](CONTRIBUTING.md) for the development setup and the sign-off (DCO) we ask for, and follow the [Code of Conduct](CODE_OF_CONDUCT.md). How decisions are made is in [GOVERNANCE.md](GOVERNANCE.md); what changed is in [CHANGELOG.md](CHANGELOG.md).
391
+
392
+ ## Use at your own risk
393
+
394
+ Harnis is provided **"as is", without warranties or conditions of any kind**, and the authors accept no liability for its use (Apache License 2.0, sections 7 and 8). There are no supported versions, no support and no guaranteed fixes. You are free to use, change, extend and redistribute it under the license, and when you do, you are responsible for:
395
+
396
+ * deploying, configuring, securing and operating it, including the actions agents take in your environment;
397
+ * the third-party software it relies on (Python packages such as the LGPL-licensed `psycopg` Postgres driver, container base images, Postgres, Redis, Kubernetes components) and the model providers and models you use: reviewing their licenses and terms, and obtaining any licenses you need;
398
+ * the data you send to model providers and your legal and contractual obligations.
399
+
400
+ ## License
401
+
402
+ Copyright 2026 Ahmad Karawash. Licensed under the Apache License, Version 2.0; see [LICENSE](LICENSE) and [NOTICE](NOTICE).