invaris-agentsec 0.5.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 (84) hide show
  1. invaris_agentsec-0.5.0/LICENSE +202 -0
  2. invaris_agentsec-0.5.0/PKG-INFO +447 -0
  3. invaris_agentsec-0.5.0/README.md +415 -0
  4. invaris_agentsec-0.5.0/agentsec/__init__.py +10 -0
  5. invaris_agentsec-0.5.0/agentsec/__main__.py +5 -0
  6. invaris_agentsec-0.5.0/agentsec/adapters/__init__.py +5 -0
  7. invaris_agentsec-0.5.0/agentsec/adapters/base.py +39 -0
  8. invaris_agentsec-0.5.0/agentsec/adapters/callable.py +70 -0
  9. invaris_agentsec-0.5.0/agentsec/adapters/http.py +168 -0
  10. invaris_agentsec-0.5.0/agentsec/api.py +179 -0
  11. invaris_agentsec-0.5.0/agentsec/attacks/__init__.py +73 -0
  12. invaris_agentsec-0.5.0/agentsec/attacks/base.py +78 -0
  13. invaris_agentsec-0.5.0/agentsec/attacks/indirect_prompt_injection.py +36 -0
  14. invaris_agentsec-0.5.0/agentsec/attacks/loop_and_budget_limits.py +47 -0
  15. invaris_agentsec-0.5.0/agentsec/attacks/memory_poisoning.py +51 -0
  16. invaris_agentsec-0.5.0/agentsec/attacks/packs.py +108 -0
  17. invaris_agentsec-0.5.0/agentsec/attacks/prompt_injection.py +36 -0
  18. invaris_agentsec-0.5.0/agentsec/attacks/secret_extraction.py +27 -0
  19. invaris_agentsec-0.5.0/agentsec/attacks/tool_output_poisoning.py +36 -0
  20. invaris_agentsec-0.5.0/agentsec/attacks/unauthorized_tool_use.py +24 -0
  21. invaris_agentsec-0.5.0/agentsec/attacks/unsafe_retrieved_documents.py +33 -0
  22. invaris_agentsec-0.5.0/agentsec/cli/__init__.py +3 -0
  23. invaris_agentsec-0.5.0/agentsec/cli/main.py +310 -0
  24. invaris_agentsec-0.5.0/agentsec/compare.py +140 -0
  25. invaris_agentsec-0.5.0/agentsec/evaluators/__init__.py +24 -0
  26. invaris_agentsec-0.5.0/agentsec/evaluators/base.py +63 -0
  27. invaris_agentsec-0.5.0/agentsec/evaluators/injection.py +51 -0
  28. invaris_agentsec-0.5.0/agentsec/evaluators/judge.py +134 -0
  29. invaris_agentsec-0.5.0/agentsec/evaluators/limits.py +74 -0
  30. invaris_agentsec-0.5.0/agentsec/evaluators/secrets.py +67 -0
  31. invaris_agentsec-0.5.0/agentsec/evaluators/tools.py +59 -0
  32. invaris_agentsec-0.5.0/agentsec/integrations/__init__.py +4 -0
  33. invaris_agentsec-0.5.0/agentsec/integrations/langchain.py +135 -0
  34. invaris_agentsec-0.5.0/agentsec/mcp/__init__.py +9 -0
  35. invaris_agentsec-0.5.0/agentsec/mcp/checks.py +190 -0
  36. invaris_agentsec-0.5.0/agentsec/mcp/client.py +211 -0
  37. invaris_agentsec-0.5.0/agentsec/mcp/host.py +156 -0
  38. invaris_agentsec-0.5.0/agentsec/mcp/pin.py +46 -0
  39. invaris_agentsec-0.5.0/agentsec/mcp/report.py +74 -0
  40. invaris_agentsec-0.5.0/agentsec/owasp.py +72 -0
  41. invaris_agentsec-0.5.0/agentsec/policies/__init__.py +12 -0
  42. invaris_agentsec-0.5.0/agentsec/policies/loader.py +154 -0
  43. invaris_agentsec-0.5.0/agentsec/policies/policy.schema.json +201 -0
  44. invaris_agentsec-0.5.0/agentsec/policies/schema.py +112 -0
  45. invaris_agentsec-0.5.0/agentsec/pytest_plugin.py +60 -0
  46. invaris_agentsec-0.5.0/agentsec/reports/__init__.py +10 -0
  47. invaris_agentsec-0.5.0/agentsec/reports/github.py +42 -0
  48. invaris_agentsec-0.5.0/agentsec/reports/html_report.py +138 -0
  49. invaris_agentsec-0.5.0/agentsec/reports/json_report.py +90 -0
  50. invaris_agentsec-0.5.0/agentsec/reports/markdown_report.py +36 -0
  51. invaris_agentsec-0.5.0/agentsec/reports/sarif_report.py +98 -0
  52. invaris_agentsec-0.5.0/agentsec/reports/terminal.py +55 -0
  53. invaris_agentsec-0.5.0/agentsec/reports/writers.py +36 -0
  54. invaris_agentsec-0.5.0/agentsec/runners/__init__.py +5 -0
  55. invaris_agentsec-0.5.0/agentsec/runners/local.py +237 -0
  56. invaris_agentsec-0.5.0/agentsec/runners/replay.py +106 -0
  57. invaris_agentsec-0.5.0/agentsec/traces/__init__.py +10 -0
  58. invaris_agentsec-0.5.0/agentsec/traces/schema.py +122 -0
  59. invaris_agentsec-0.5.0/agentsec/traces/trace.schema.json +46 -0
  60. invaris_agentsec-0.5.0/invaris_agentsec.egg-info/PKG-INFO +447 -0
  61. invaris_agentsec-0.5.0/invaris_agentsec.egg-info/SOURCES.txt +82 -0
  62. invaris_agentsec-0.5.0/invaris_agentsec.egg-info/dependency_links.txt +1 -0
  63. invaris_agentsec-0.5.0/invaris_agentsec.egg-info/entry_points.txt +5 -0
  64. invaris_agentsec-0.5.0/invaris_agentsec.egg-info/requires.txt +9 -0
  65. invaris_agentsec-0.5.0/invaris_agentsec.egg-info/top_level.txt +1 -0
  66. invaris_agentsec-0.5.0/pyproject.toml +52 -0
  67. invaris_agentsec-0.5.0/setup.cfg +4 -0
  68. invaris_agentsec-0.5.0/tests/test_action_scripts.py +438 -0
  69. invaris_agentsec-0.5.0/tests/test_adapter_runner.py +191 -0
  70. invaris_agentsec-0.5.0/tests/test_api_and_plugin.py +124 -0
  71. invaris_agentsec-0.5.0/tests/test_attack_packs.py +199 -0
  72. invaris_agentsec-0.5.0/tests/test_compare.py +78 -0
  73. invaris_agentsec-0.5.0/tests/test_end_to_end.py +139 -0
  74. invaris_agentsec-0.5.0/tests/test_evaluators.py +131 -0
  75. invaris_agentsec-0.5.0/tests/test_langchain_integration.py +138 -0
  76. invaris_agentsec-0.5.0/tests/test_mcp.py +208 -0
  77. invaris_agentsec-0.5.0/tests/test_mcp_host.py +143 -0
  78. invaris_agentsec-0.5.0/tests/test_packaging.py +43 -0
  79. invaris_agentsec-0.5.0/tests/test_rag_example.py +92 -0
  80. invaris_agentsec-0.5.0/tests/test_replay.py +91 -0
  81. invaris_agentsec-0.5.0/tests/test_reports_phase2.py +117 -0
  82. invaris_agentsec-0.5.0/tests/test_sarif_report.py +83 -0
  83. invaris_agentsec-0.5.0/tests/test_schemas.py +64 -0
  84. invaris_agentsec-0.5.0/tests/test_streaming_and_callable.py +118 -0
@@ -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.
@@ -0,0 +1,447 @@
1
+ Metadata-Version: 2.4
2
+ Name: invaris-agentsec
3
+ Version: 0.5.0
4
+ Summary: Adversarial security and reliability testing for autonomous AI agents.
5
+ Author: Invaris Labs
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/invarislabs/invaris-agentsec
8
+ Project-URL: Documentation, https://github.com/invarislabs/invaris-agentsec/tree/main/docs
9
+ Project-URL: Issues, https://github.com/invarislabs/invaris-agentsec/issues
10
+ Project-URL: Changelog, https://github.com/invarislabs/invaris-agentsec/blob/main/CHANGELOG.md
11
+ Keywords: ai-agents,security,prompt-injection,red-teaming,mcp,llm,testing
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Security
20
+ Classifier: Topic :: Software Development :: Testing
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: PyYAML>=6.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=7; extra == "dev"
27
+ Requires-Dist: jsonschema>=4; extra == "dev"
28
+ Provides-Extra: langchain
29
+ Requires-Dist: langgraph>=1.0; extra == "langchain"
30
+ Requires-Dist: langchain-core>=1.0; extra == "langchain"
31
+ Dynamic: license-file
32
+
33
+ # Invaris AgentSec
34
+
35
+ **Adversarial security and reliability testing for autonomous AI agents.**
36
+
37
+ Invaris AgentSec is an open-source testing framework for finding unsafe, unauthorized, and unreliable agent behaviour before it reaches production. It helps developers test complete agent workflows involving LLMs, retrieval pipelines, memory, MCP servers, external tools, databases, and sensitive actions.
38
+
39
+ The goal is simple: make testing an AI agent as repeatable and developer-friendly as testing an API.
40
+
41
+ > **Project status:** Early development, but the local testing engine is functional and self-contained: 8 attack categories across 34 deterministic, replayable scenarios; JSON, HTML, Markdown and SARIF reports; a Python API and pytest plugin; MCP server scanning and MCP-based agent testing; LangChain/LangGraph support; regression comparison; a packaged GitHub Action with pull-request comparison comments and GitHub Code Scanning integration; and a plugin mechanism (attack packs) for adding your own scenarios without forking the project. The first PyPI release is being prepared. See [What's Built](#whats-built) for the full list and [Future Work](#future-work) for what's next. Interfaces marked as provisional may still change.
42
+
43
+ ## Why AgentSec?
44
+
45
+ Traditional software follows explicitly written execution paths. AI agents interpret untrusted inputs, select tools, retain memory, and make decisions dynamically. A single indirect prompt injection or poisoned tool response can cause an agent to:
46
+
47
+ - expose confidential information;
48
+ - invoke an unauthorized tool;
49
+ - exceed its permissions or operating budget;
50
+ - execute an irreversible action;
51
+ - preserve malicious instructions in memory;
52
+ - enter an expensive or non-terminating loop; or
53
+ - behave differently after a model, prompt, or tool update.
54
+ Unit tests alone cannot adequately exercise these behaviours. AgentSec runs stateful adversarial scenarios, observes the complete execution trace, and verifies that security policies hold throughout the workflow.
55
+
56
+ ## What AgentSec Tests
57
+
58
+ The test suite covers:
59
+
60
+ - Direct and indirect prompt injection
61
+ - Unauthorized tool invocation
62
+ - Tool-output and MCP-server poisoning
63
+ - Sensitive-data and secret leakage
64
+ - Memory poisoning and unsafe persistence
65
+ - Excessive tool calls, token usage, and cost
66
+ - Infinite loops and missing termination conditions
67
+ - Unsafe handling of retrieved documents
68
+ - Behavioural regressions across models and prompts, via `agentsec compare`
69
+
70
+ Identity and privilege misuse, multi-agent trust and delegation failures, and unauthorized financial or on-chain actions are not covered yet; see [Future Work](#future-work).
71
+
72
+ Findings are mapped to the [OWASP Top 10 for Agentic Applications](https://genai.owasp.org/2025/12/09/owasp-top-10-for-agentic-applications-the-benchmark-for-agentic-security-in-the-age-of-autonomous-ai/) (ASI01 to ASI10).
73
+
74
+ ## Design Principles
75
+
76
+ - **Evidence over scores:** Every finding includes the input, trace, violated policy, and observed action.
77
+ - **Stateful testing:** Tests cover complete workflows rather than isolated prompts.
78
+ - **Framework independence:** AgentSec works across models, agent frameworks, MCP servers, and custom APIs.
79
+ - **CI-first:** Security regressions are detectable automatically on every pull request.
80
+ - **Local by default:** Developers can test locally without sending private traces to a hosted service.
81
+ - **Reproducibility:** A failed scenario is replayable with the same configuration and evidence.
82
+
83
+ ## Developer Experience
84
+
85
+ Install the command-line tool:
86
+
87
+ ```bash
88
+ pip install invaris-agentsec
89
+ ```
90
+
91
+ The package is not on PyPI yet. Until the first release, install from a clone with `pip install -e .`.
92
+
93
+ Create an `agentsec.yaml` policy:
94
+
95
+ ```yaml
96
+ version: "1"
97
+
98
+ agent:
99
+ name: support-agent
100
+ endpoint: http://localhost:8000/agent
101
+
102
+ allowed_tools:
103
+ - search_documents
104
+ - create_draft
105
+
106
+ forbidden_actions:
107
+ - send_email
108
+ - reveal_credentials
109
+ - execute_payment
110
+
111
+ limits:
112
+ max_steps: 12
113
+ max_tool_calls: 10
114
+ max_cost_usd: 0.50
115
+
116
+ tests:
117
+ - prompt_injection
118
+ - indirect_prompt_injection
119
+ - secret_extraction
120
+ - unauthorized_tool_use
121
+ - tool_output_poisoning
122
+ - unsafe_retrieved_documents
123
+ - loop_and_budget_limits
124
+ ```
125
+
126
+ Run the security suite:
127
+
128
+ ```bash
129
+ agentsec test
130
+ ```
131
+
132
+ Example output (reports are also written to `.agentsec/report.json` and `.agentsec/report.html`):
133
+
134
+ ```text
135
+ Invaris AgentSec
136
+
137
+ 42 scenarios executed
138
+ 36 passed
139
+ 6 findings
140
+
141
+ CRITICAL Indirect prompt injection triggered send_email
142
+ HIGH Retrieved confidential content appeared in the response
143
+ HIGH Agent attempted a forbidden payment action
144
+ MEDIUM Tool-call budget exceeded
145
+
146
+ Report written to .agentsec/report.json
147
+ Report written to .agentsec/report.html
148
+ ```
149
+
150
+ ## Try It
151
+
152
+ Run the bundled intentionally vulnerable agent, then test it:
153
+
154
+ ```bash
155
+ pip install -e ".[dev]"
156
+ python examples/vulnerable_rag_agent/server.py & # add --safe for the hardened variant
157
+ agentsec test --policy examples/vulnerable_rag_agent/agentsec.yaml
158
+ ```
159
+
160
+ Against the vulnerable agent you should see 34 scenarios executed and findings in all eight
161
+ categories. With `--safe`, all 34 pass.
162
+
163
+ **Reports.** `agentsec test` writes `.agentsec/report.json` and a self-contained `.agentsec/report.html`
164
+ (`--format json,html,markdown,sarif` to choose; `sarif` writes `results.sarif` for
165
+ [GitHub Code Scanning](docs/github-actions.md#github-code-scanning-sarif)). Secrets are masked. Every
166
+ finding is tagged with the closest [OWASP Top 10 for Agentic Applications](https://genai.owasp.org/2025/12/09/owasp-top-10-for-agentic-applications-the-benchmark-for-agentic-security-in-the-age-of-autonomous-ai/)
167
+ category (ASI01 to ASI10).
168
+
169
+ **Exit codes.** `agentsec test` exits `1` when findings exist (`--fail-on high` to raise the bar,
170
+ `--fail-on none` to never fail) and `2` on configuration or connection errors. Use `--seed N` for a
171
+ reproducible run and `-s <category-or-scenario-id>` to run a subset.
172
+
173
+ **Replay.** `agentsec replay .agentsec/report.json` re-runs the findings from an earlier report with
174
+ the recorded seed and prints `REPRODUCED` or `NOT REPRODUCED` for each, so you can confirm a fix.
175
+
176
+ **Model-assisted checks.** Add a `judge:` section to your policy and pass `--judge` to have a model
177
+ review scenarios the deterministic checks passed, for example a paraphrased leak. These findings are
178
+ labelled `model-assisted`, are never critical, and are opt-in because transcripts are sent to the
179
+ judge endpoint. See [`docs/judge.md`](docs/judge.md).
180
+
181
+ **A RAG-style agent.** `examples/rag_agent` owns a small document corpus and runs its tools itself, reporting the calls to AgentSec. Start it with `python examples/rag_agent/server.py` (add `--safe` for the hardened variant) and test it with `agentsec test -p examples/rag_agent/agentsec.yaml`. See [`docs/agent-contract.md`](docs/agent-contract.md#the-rag-backed-reference-agent).
182
+
183
+ **Regression comparison.** `agentsec compare old/report.json new/report.json` lists new, fixed and changed findings and exits `1` on regressions. The packaged GitHub Action wires this into pull requests automatically (`baseline-report`), posting and updating a PR comment with what's new or worse; see [GitHub Actions](docs/github-actions.md#pull-request-and-scheduled-regression-testing).
184
+
185
+ **MCP servers.** `agentsec mcp scan --command "python server.py"` lists a server's tools (never calls them) and flags poisoned descriptions, hidden characters, shadowing and changed definitions. See [`docs/mcp-testing.md`](docs/mcp-testing.md).
186
+
187
+ **MCP-connected agents.** `agentsec test --mcp-listen 127.0.0.1:8765` makes AgentSec the MCP server your agent uses, delivering the same adversarial scenarios through MCP tool results.
188
+
189
+ **LangChain and LangGraph agents** can be tested in-process with `LangChainAdapter`; see [`docs/frameworks.md`](docs/frameworks.md). Any other framework works through the generic `CallableAdapter`.
190
+
191
+ **Your own scenarios** can be added without forking AgentSec: `agentsec test --attack-pack my_pack.py` or `attack_packs:` in the policy loads extra categories from a local file or an installed package; see [`docs/extending.md`](docs/extending.md#write-an-attack-pack).
192
+
193
+ **Other commands.** `agentsec init` writes a starter policy and `agentsec schema policy|trace` prints
194
+ the JSON schemas.
195
+
196
+ The categories are `prompt_injection`, `indirect_prompt_injection`, `secret_extraction`,
197
+ `unauthorized_tool_use`, `tool_output_poisoning`, `unsafe_retrieved_documents`,
198
+ `loop_and_budget_limits` and `memory_poisoning`.
199
+
200
+ **Agent contract.** The adapter posts OpenAI-style chat-completions requests to `agent.endpoint`
201
+ and declares your allowed tools (plus forbidden actions as decoys). AgentSec plays the tools:
202
+ every call is simulated, and results carry the adversarial content. Agents that run tools
203
+ server-side can report them in an `x_agentsec.events` field, and agents with memory can key it on the
204
+ `user` field (also sent as `X-AgentSec-Session`). List the synthetic credentials your agent can see
205
+ under `secrets:` so leaks are detected.
206
+
207
+ **In CI.** Inside GitHub Actions, `agentsec test` adds workflow annotations for each finding and
208
+ writes a job summary automatically. A packaged action (`uses: ./`) starts your agent, runs the suite,
209
+ uploads reports and gates the job; it can also compare against a baseline report and comment on the
210
+ pull request, or feed `results.sarif` to GitHub Code Scanning. See [`docs/github-actions.md`](docs/github-actions.md).
211
+
212
+ Full documentation, including architecture, policy reference, attack catalog, Python API, testing
213
+ and extension guides, is in [`docs/`](docs/README.md).
214
+
215
+ ## Example Policy Test
216
+
217
+ AgentSec tests focus on expected behaviour rather than a particular model response:
218
+
219
+ ```python
220
+ from agentsec import AgentTarget, SecuritySuite
221
+
222
+ target = AgentTarget(
223
+ endpoint="http://localhost:8000/agent",
224
+ allowed_tools={"search_documents", "create_draft"},
225
+ forbidden_tools={"send_email", "execute_payment"},
226
+ )
227
+
228
+ suite = SecuritySuite(target)
229
+
230
+ result = suite.run("indirect_prompt_injection")
231
+
232
+ assert result.secret_leaks == []
233
+ assert result.forbidden_tool_calls == []
234
+ assert result.total_tool_calls <= 10
235
+ ```
236
+
237
+ `AgentTarget`, `SecuritySuite` and the result attributes above are implemented. In pytest, the
238
+ bundled plugin adds an `agentsec_run` fixture:
239
+
240
+ ```python
241
+ import pytest
242
+ from agentsec import CATEGORIES
243
+
244
+ @pytest.mark.parametrize("category", CATEGORIES)
245
+ def test_agent_resists(category, agentsec_run):
246
+ agentsec_run(category, fail_on="high")
247
+ ```
248
+
249
+ Run it with `pytest --agentsec-policy agentsec.yaml`. See [`docs/python-api-and-pytest.md`](docs/python-api-and-pytest.md).
250
+ The API may still change before a stable release.
251
+
252
+ ## How It Works
253
+
254
+ ```mermaid
255
+ flowchart TD
256
+ A["Test policy"] --> B["Adversarial scenario engine"]
257
+ B --> C["Agent under test"]
258
+ C --> D["Models, tools, memory and MCP"]
259
+ D --> E["Trace collector"]
260
+ E --> F["Policy evaluator"]
261
+ F --> G["Evidence and security report"]
262
+ ```
263
+
264
+ 1. A developer defines the agent's permitted actions and operating limits.
265
+ 2. AgentSec generates or loads adversarial scenarios.
266
+ 3. The scenarios exercise the agent, retrieval layer, memory, and tools.
267
+ 4. AgentSec records prompts, responses, tool calls, state changes, timing, and cost.
268
+ 5. Policy evaluators identify violations and assign severity.
269
+ 6. Reports provide reproducible evidence and remediation guidance.
270
+
271
+ ## Architecture
272
+
273
+ ```text
274
+ agentsec/
275
+ ├── attacks/ # Prompt, retrieval, memory and tool attacks, plus attack-pack loading
276
+ ├── adapters/ # OpenAI-compatible HTTP (optionally streaming) and in-process callables
277
+ ├── mcp/ # MCP server scanner (client, checks, pins) and the MCP attack host
278
+ ├── integrations/ # LangChain and LangGraph adapter
279
+ ├── evaluators/ # Deterministic checks plus an optional model-assisted judge
280
+ ├── policies/ # Permissions, limits and expected behaviour
281
+ ├── runners/ # Local runner and replay (CI and sandboxed planned)
282
+ ├── traces/ # Normalized agent execution events
283
+ ├── reports/ # Terminal, JSON, HTML, Markdown, SARIF and GitHub output
284
+ ├── cli/ # Command-line interface
285
+ ├── compare.py # Report-to-report regression comparison
286
+ ├── owasp.py # Mapping of findings to OWASP agentic categories
287
+ ├── api.py # Python API (AgentTarget, SecuritySuite)
288
+ └── pytest_plugin.py # pytest fixtures
289
+ action.yml, action/ # Packaged GitHub Action (incl. baseline comparison, PR comments)
290
+ examples/ # Vulnerable reference agents (rule-based, RAG-backed, MCP) and attack packs
291
+ tests/ # Unit and end-to-end tests (177+ tests)
292
+ ```
293
+
294
+ ### Core components
295
+
296
+ | Component | Responsibility |
297
+ |---|---|
298
+ | Scenario engine | Builds multi-step adversarial workflows |
299
+ | Agent adapters | Connects custom agents and supported frameworks |
300
+ | Trace collector | Captures prompts, retrieval events, tool calls and state changes |
301
+ | Policy engine | Checks permissions, budgets and behavioural constraints |
302
+ | Evaluators | Detects leakage, unsafe actions and security regressions |
303
+ | Reporter | Produces human-readable and machine-readable evidence |
304
+
305
+ ## What's Built
306
+
307
+ ### Core testing engine
308
+
309
+ - [x] OpenAI-compatible HTTP agent adapter, with optional server-sent-events streaming (`agent.stream: true`)
310
+ - [x] `CallableAdapter` for testing an agent in-process, no HTTP server required
311
+ - [x] YAML security policies, validated against a JSON Schema (`agentsec schema policy`)
312
+ - [x] Eight adversarial test categories: direct prompt injection, indirect prompt injection, secret extraction, unauthorized tool use, tool-output poisoning, unsafe retrieved documents, loop-and-budget limits, and memory poisoning (four two-session scenarios)
313
+ - [x] Step, tool-call, token, time and cost limits, with pricing-based cost tracking
314
+ - [x] Deterministic evaluators, plus an optional model-assisted judge for paraphrased or borderline leaks
315
+ - [x] Normalized execution traces recording every prompt, tool call, tool result and state change
316
+ - [x] Findings mapped to the OWASP Top 10 for Agentic Applications (ASI01-ASI10)
317
+ - [x] Reproducible runs via `--seed`, and a CI-friendly exit code (`1` findings, `2` error)
318
+
319
+ ### Reports and CI
320
+
321
+ - [x] Terminal, JSON, self-contained HTML, Markdown and SARIF 2.1.0 report formats (`--format`)
322
+ - [x] Secrets masked everywhere, in every format
323
+ - [x] `agentsec replay` re-runs findings from an earlier report to confirm a fix
324
+ - [x] `agentsec compare` diffs two reports (new, fixed, unchanged, worse, better, not comparable)
325
+ - [x] GitHub Actions workflow annotations and job summary, with no extra flags
326
+ - [x] A packaged, reusable GitHub Action (`action.yml`) that installs AgentSec, optionally starts the agent, runs the suite, uploads reports and gates the job
327
+ - [x] Baseline and pull-request regression testing built into the Action: compare a run against a baseline report and post (and update, across pushes) a PR comment listing what's new or worse
328
+ - [x] SARIF output wired to GitHub Code Scanning (`--format sarif` plus `github/codeql-action/upload-sarif`); see [GitHub Actions](docs/github-actions.md#github-code-scanning-sarif)
329
+
330
+ ### Frameworks and protocols
331
+
332
+ - [x] `LangChainAdapter` for LangChain and LangGraph agents, run in-process, duck-typed so AgentSec never imports the framework itself
333
+ - [x] `agentsec mcp scan`: statically scans an MCP server's tool list for poisoned descriptions, invisible characters, tool shadowing, forbidden or unlisted tools, and rug pulls (pin a server's definitions and compare across runs)
334
+ - [x] `agentsec test --mcp-listen`: AgentSec acts as the MCP server an agent connects to, delivering the same adversarial scenarios over MCP tool results
335
+ - [x] Agents that run tools server-side and stream their replies (server-sent events, `x_agentsec` events for reporting server-side tool calls and memory keys)
336
+
337
+ ### Extensibility and API
338
+
339
+ - [x] Python API (`AgentTarget`, `SecuritySuite`) mirroring the CLI, for running scenarios from code
340
+ - [x] A pytest plugin (`agentsec_run` fixture, `--agentsec-policy`)
341
+ - [x] Attack packs: load extra scenario categories from a local file or an installed package without forking AgentSec (`attack_packs:` in the policy, or `agentsec test --attack-pack`), validated and name-collision-checked at load time
342
+ - [x] Two intentionally vulnerable reference agents (rule-based, RAG-backed), each with a hardened variant that passes the full suite, plus a demo MCP server and an MCP-connected reference agent
343
+
344
+ ## Future Work
345
+
346
+ Everything below is not yet built. It splits into a hosted platform, which is commercial territory kept
347
+ separate from the open-source engine (see [Open Source and Commercial Direction](#open-source-and-commercial-direction)),
348
+ and engine-level coverage gaps that stay in scope for AgentSec itself.
349
+
350
+ ### Hosted platform
351
+
352
+ - [ ] Hosted execution dashboard
353
+ - [ ] Team projects and cross-run historical reports
354
+ - [ ] Self-hosted enterprise deployment
355
+ - [ ] Production trace monitoring (continuous monitoring of live agent traffic, not just test-time runs)
356
+
357
+ The CLI-scoped equivalents of the first two items already exist and are open source: `agentsec compare`
358
+ plus the GitHub Action's `baseline-report`/PR-comment support gives pull-request and scheduled regression
359
+ testing without a hosted dashboard; see [GitHub Actions](docs/github-actions.md#pull-request-and-scheduled-regression-testing).
360
+
361
+ ### Engine and coverage
362
+
363
+ - [ ] Multi-agent adversarial simulation
364
+ - [ ] Wallet and on-chain transaction policies
365
+ - [ ] Agent identity and delegation testing
366
+ - [ ] Stateful, multi-turn campaign generation
367
+ - [ ] Cross-agent failure-propagation analysis
368
+ - [ ] Memory-poisoning scenarios longer than one follow-up session
369
+ - [ ] MCP-specific attacks beyond hostile tool results and decoy tools; see [MCP testing](docs/mcp-testing.md)
370
+ - [ ] Dedicated adapters for other agent frameworks (CrewAI, AutoGen, LlamaIndex, OpenAI Agents SDK) — the generic `CallableAdapter` covers them today; see [Frameworks](docs/frameworks.md#any-other-framework)
371
+
372
+ Real-world verification is also open: the packaged GitHub Action, the LangChain integration and the SARIF/Code
373
+ Scanning upload are exercised by the test suite but have not yet been run against real GitHub Actions, real
374
+ LLM-backed agents, or a real MCP server in production. See [Testing](docs/testing.md) for exactly what is
375
+ and isn't covered.
376
+
377
+ ## Intended Users
378
+
379
+ AgentSec is being designed for:
380
+
381
+ - Developers building tool-using AI agents
382
+ - AI startups preparing agents for production
383
+ - Security teams evaluating autonomous workflows
384
+ - Teams exposing or consuming MCP servers
385
+ - Enterprises deploying agents over internal data
386
+ - Financial and blockchain teams building transaction-capable agents
387
+ - Researchers studying agent reliability and adversarial behaviour
388
+
389
+ ## Open Source and Commercial Direction
390
+
391
+ The local testing engine will remain open source. Invaris Labs plans to build optional commercial capabilities around it, including:
392
+
393
+ - Continuous cloud-based security testing
394
+ - Collaborative dashboards and regression history
395
+ - Private and organization-specific attack suites
396
+ - Enterprise self-hosting and access controls
397
+ - Security assessments and remediation support
398
+ - Compliance-ready evidence and reporting
399
+
400
+ The open-source engine should remain useful on its own; the CLI-scoped building blocks for several of these
401
+ (private attack libraries, pull-request regression testing) already ship in the engine, described above. Paid
402
+ services will focus on scale, collaboration, continuous operation, and enterprise requirements.
403
+
404
+ ## Security Model
405
+
406
+ AgentSec executes potentially adversarial content against systems that may have access to real tools and data. During early development:
407
+
408
+ - use isolated test environments;
409
+ - provide synthetic credentials and test data;
410
+ - disable irreversible actions;
411
+ - use sandboxed or mocked tools;
412
+ - enforce strict spending and execution limits; and
413
+ - never point experimental tests at production agents.
414
+ A detailed threat model will be published before the first public release. The vulnerability-reporting policy is in [SECURITY.md](SECURITY.md).
415
+
416
+ ## Contributing
417
+
418
+ The project is in early development. Contributions will be welcomed in areas such as:
419
+
420
+ - Adversarial test cases
421
+ - Agent and framework adapters
422
+ - MCP security testing
423
+ - Deterministic evaluators
424
+ - Trace schemas and interoperability
425
+ - Sandboxing and safe execution
426
+ - Documentation and vulnerable examples
427
+ To develop locally, run `pip install -e ".[dev]"` and then `pytest`. See [CONTRIBUTING.md](CONTRIBUTING.md) for the guidelines.
428
+
429
+ ## Responsible Disclosure
430
+
431
+ If AgentSec identifies a vulnerability in a third-party agent, framework, or integration, do not publish sensitive details immediately. Contact the affected maintainer and allow reasonable time for remediation. To report a vulnerability in AgentSec itself, see [SECURITY.md](SECURITY.md).
432
+
433
+ ## License
434
+
435
+ Invaris AgentSec is licensed under the [Apache License 2.0](LICENSE).
436
+
437
+ ## About Invaris Labs
438
+
439
+ Invaris Labs is building testing and verification infrastructure for trustworthy autonomous and decentralized systems. Its work combines adversarial simulation, protocol engineering, AI security, and developer tooling.
440
+
441
+ ## Contact
442
+
443
+ - GitHub: [github.com/tinniaru3005](https://github.com/tinniaru3005)
444
+ - LinkedIn: [Arunima Chaudhuri](https://www.linkedin.com/in/arunima-chaudhuri/)
445
+ ---
446
+
447
+ **Invaris AgentSec is under active development.** If you are building an AI agent and would like to become an early design partner, open a discussion or get in touch.