Skip to content

Commit ecdb203

Browse files
author
Divyanshu Jethi
committed
feat: initial release of agentshield Python SDK v0.2.1
0 parents  commit ecdb203

15 files changed

Lines changed: 600 additions & 0 deletions

‎.github/workflows/python-tests.yml‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Python CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ["3.10", "3.11", "3.12", "3.13"]
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python ${{ matrix.python-version }}
20+
uses: actions/setup-python@v5
21+
with:
22+
python-version: ${{ matrix.python-version }}
23+
24+
- name: Install dependencies
25+
run: |
26+
python -m pip install --upgrade pip
27+
pip install -e .
28+
29+
- name: Run Test Suite
30+
run: |
31+
python tests/test_redactor.py
32+
python tests/test_sandbox.py

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 RitualDev Studio (Divyanshu Jethi & Sakshi Sharma)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md‎

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<div align="center">
2+
3+
# AgentShield Python SDK 🛡️
4+
5+
[![PyPI version](https://img.shields.io/badge/PyPI-agentshield-3776AB?style=for-the-badge&logo=pypi&logoColor=white)](https://pypi.org/project/agentshield/)
6+
[![Python 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue?style=for-the-badge&logo=python&logoColor=white)](https://www.python.org/)
7+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
8+
[![Interactive Playground](https://img.shields.io/badge/Playground-Live%20Demo-00F59B?style=for-the-badge)](https://ritualdev.in/playground)
9+
[![Trust Center](https://img.shields.io/badge/Trust-SIG%20Lite%20%2F%20DPDP-00D4FF?style=for-the-badge)](https://ritualdev.in/trust)
10+
11+
> Enterprise-grade Zero-Leak Secret Defense & Sandbox for Autonomous AI Agents built with LangGraph, CrewAI, AutoGen, Smolagents, and OpenAI Swarm.
12+
13+
[Documentation](https://ritualdev.in/docs) • [Web Portal](https://ritualdev.in) • [Trust Center](https://ritualdev.in/trust) • [Issues](https://github.com/RitualDev-Lab/agentshield-python/issues)
14+
15+
</div>
16+
17+
---
18+
19+
## ⚡ Why AgentShield for Python AI Agents?
20+
21+
Autonomous AI coding agents frequently:
22+
1. Print or dump `/proc/self/environ` to inspect credentials.
23+
2. Leak raw `OPENAI_API_KEY`, `AWS_SECRET_ACCESS_KEY`, or database credentials into LLM completion prompts.
24+
3. Fall victim to prompt injection attacks attempting to exfiltrate `.env` files.
25+
26+
`agentshield` intercepts, redacts, and cryptographically seals sensitive data with linear-time token verification before any byte leaves your runtime or enters an LLM prompt.
27+
28+
---
29+
30+
## 📦 Installation
31+
32+
```bash
33+
pip install agentshield
34+
```
35+
36+
Or install with LangChain support:
37+
38+
```bash
39+
pip install "agentshield[langchain]"
40+
```
41+
42+
---
43+
44+
## 🚀 Quickstart
45+
46+
### 1. Zero-Leak Secret Redactor
47+
48+
```python
49+
from agentshield import AgentShieldRedactor
50+
51+
redactor = AgentShieldRedactor()
52+
53+
agent_output = """
54+
Calling AWS deployment:
55+
AWS_ACCESS_KEY: AKIAIOSFODNN7EXAMPLE
56+
OPENAI_KEY: sk-1234567890abcdef1234567890abcdef
57+
Check /proc/self/environ
58+
"""
59+
60+
result = redactor.redact(agent_output)
61+
62+
print(result.clean_text)
63+
# Output:
64+
# Calling AWS deployment:
65+
# AWS_ACCESS_KEY: [AGENTSHIELD_REDACTED:AWS_ACCESS_KEY:a1b2c3d4e5f6]
66+
# OPENAI_KEY: [AGENTSHIELD_REDACTED:OPENAI_KEY:9f8e7d6c5b4a]
67+
# Check [AGENTSHIELD_REDACTED:PROC_ENVIRON_READ:3c4d5e6f7a8b]
68+
69+
print(f"Redacted {result.redacted_count} secrets in {result.latency_ms}ms")
70+
print(f"HMAC Audit Ledger Seal: {result.audit_hash}")
71+
```
72+
73+
---
74+
75+
### 2. LangGraph & LangChain Integration
76+
77+
Attach `AgentShieldCallbackHandler` to your agent pipeline:
78+
79+
```python
80+
from langchain_openai import ChatOpenAI
81+
from agentshield.integrations.langchain import AgentShieldCallbackHandler
82+
83+
shield = AgentShieldCallbackHandler()
84+
85+
llm = ChatOpenAI(
86+
model="gpt-4o",
87+
callbacks=[shield]
88+
)
89+
90+
# All outgoing prompts and tool calls are automatically audited and sanitized
91+
```
92+
93+
---
94+
95+
### 3. CrewAI Safety Hook
96+
97+
```python
98+
from crewai import Agent, Task, Crew
99+
from agentshield.integrations.crewai import AgentShieldCrewHook
100+
101+
hook = AgentShieldCrewHook()
102+
103+
task = Task(
104+
description="Analyze server environment and deploy database",
105+
expected_output="Deployment summary"
106+
)
107+
108+
# Pre-execution and post-execution hooks sanitize credentials
109+
hook.before_task_execution(task)
110+
```
111+
112+
---
113+
114+
### 4. Sandboxed Subprocess Execution
115+
116+
Prevent child processes spawned by agents from reading raw host environment secrets:
117+
118+
```python
119+
from agentshield import AgentShieldSandbox
120+
121+
sandbox = AgentShieldSandbox()
122+
123+
# Executes in an isolated environment with credentials virtualized to mock tokens
124+
result = sandbox.run_command(["python", "untrusted_agent_script.py"], timeout=15)
125+
print(result.clean_text)
126+
```
127+
128+
---
129+
130+
## 🔒 Security & Statutory Compliance
131+
132+
- **Zero Cloud Telemetry**: Runs 100% locally with `AGENTSHIELD_AIR_GAPPED=1`.
133+
- **Pre-filled SIG Lite / CAIQ**: Download the Vendor Risk Assessment Packet at [ritualdev.in/trust](https://ritualdev.in/trust).
134+
- **Statutory Controls**: Architected for **India DPDP Act 2023**, **EU GDPR**, and **SOC 2 Type II**.
135+
136+
---
137+
138+
## 📄 License
139+
140+
MIT © [RitualDev Studio](https://ritualdev.in)

‎pyproject.toml‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
[build-system]
2+
requires = ["setuptools>=61.0", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "agentshield"
7+
version = "0.2.1"
8+
description = "Enterprise Zero-Leak Secret Defense & Sandbox for Autonomous AI Agents (LangGraph, CrewAI, AutoGen)"
9+
readme = "README.md"
10+
authors = [
11+
{ name = "RitualDev Studio", email = "developer@ritualdev.com" },
12+
{ name = "Divyanshu Jethi", email = "divyanshujethi@ritualdev.com" }
13+
]
14+
license = { text = "MIT" }
15+
keywords = [
16+
"ai-agents",
17+
"agent-security",
18+
"zero-leak",
19+
"sandboxing",
20+
"langchain",
21+
"crewai",
22+
"secret-redaction",
23+
"llm-guardrails"
24+
]
25+
classifiers = [
26+
"Development Status :: 4 - Beta",
27+
"Intended Audience :: Developers",
28+
"License :: OSI Approved :: MIT License",
29+
"Programming Language :: Python :: 3",
30+
"Programming Language :: Python :: 3.10",
31+
"Programming Language :: Python :: 3.11",
32+
"Programming Language :: Python :: 3.12",
33+
"Programming Language :: Python :: 3.13",
34+
"Topic :: Security",
35+
"Topic :: Scientific/Engineering :: Artificial Intelligence"
36+
]
37+
requires-python = ">=3.10"
38+
dependencies = []
39+
40+
[project.optional-dependencies]
41+
dev = [
42+
"pytest>=7.0.0",
43+
"pytest-cov>=4.0.0",
44+
"ruff>=0.1.0"
45+
]
46+
langchain = [
47+
"langchain-core>=0.1.0"
48+
]
49+
50+
[project.urls]
51+
Homepage = "https://ritualdev.in/agentshield"
52+
Documentation = "https://ritualdev.in/docs"
53+
TrustCenter = "https://ritualdev.in/trust"
54+
Repository = "https://github.com/RitualDev-Lab/agentshield-python"
55+
Playground = "https://ritualdev.in/playground"
56+
57+
[tool.setuptools.packages.find]
58+
where = ["src"]

‎src/agentshield/__init__.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
"""
2+
AgentShield Python SDK
3+
Enterprise Zero-Leak Secret Defense & Sandbox for Autonomous AI Agents.
4+
"""
5+
6+
from agentshield.redactor import AgentShieldRedactor, RedactionResult
7+
from agentshield.sandbox import AgentShieldSandbox, sanitize_env
8+
9+
__version__ = "0.2.1"
10+
__all__ = [
11+
"AgentShieldRedactor",
12+
"RedactionResult",
13+
"AgentShieldSandbox",
14+
"sanitize_env",
15+
]
530 Bytes
Binary file not shown.
6.84 KB
Binary file not shown.
4.88 KB
Binary file not shown.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Any, Optional
2+
from agentshield.redactor import AgentShieldRedactor
3+
4+
class AgentShieldCrewHook:
5+
"""
6+
CrewAI task and agent guardrail hook.
7+
Ensures agent task outputs and tool executions never expose sensitive keys.
8+
"""
9+
10+
def __init__(self, redactor: Optional[AgentShieldRedactor] = None):
11+
self.redactor = redactor or AgentShieldRedactor()
12+
13+
def before_task_execution(self, task: Any) -> None:
14+
"""Inspects task description and expected output templates."""
15+
if hasattr(task, "description") and isinstance(task.description, str):
16+
res = self.redactor.redact(task.description)
17+
task.description = res.clean_text
18+
19+
def after_task_execution(self, task_output: Any) -> Any:
20+
"""Sanitizes task result before returning to agent or next pipeline step."""
21+
if isinstance(task_output, str):
22+
res = self.redactor.redact(task_output)
23+
return res.clean_text
24+
elif hasattr(task_output, "raw") and isinstance(task_output.raw, str):
25+
res = self.redactor.redact(task_output.raw)
26+
task_output.raw = res.clean_text
27+
return task_output
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from typing import Any, Dict, List, Optional
2+
from agentshield.redactor import AgentShieldRedactor
3+
4+
class AgentShieldCallbackHandler:
5+
"""
6+
LangChain & LangGraph callback handler that inspects and redacts secrets
7+
from LLM inputs, tool execution arguments, and agent thoughts in real-time.
8+
"""
9+
10+
def __init__(self, redactor: Optional[AgentShieldRedactor] = None):
11+
self.redactor = redactor or AgentShieldRedactor()
12+
self.total_redactions = 0
13+
14+
def on_llm_start(
15+
self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
16+
) -> None:
17+
"""Inspects prompts before they leave the application boundary."""
18+
for i, prompt in enumerate(prompts):
19+
result = self.redactor.redact(prompt)
20+
if result.redacted_count > 0:
21+
self.total_redactions += result.redacted_count
22+
prompts[i] = result.clean_text
23+
24+
def on_tool_start(
25+
self, serialized: Dict[str, Any], input_str: str, **kwargs: Any
26+
) -> Any:
27+
"""Inspects tool inputs before shell or API execution."""
28+
result = self.redactor.redact(input_str)
29+
if result.redacted_count > 0:
30+
self.total_redactions += result.redacted_count
31+
return result.clean_text
32+
return input_str

0 commit comments

Comments
 (0)