Metadata-Version: 2.4
Name: securityagent-core
Version: 4.61.0
Summary: Local-first DLP engine and security layer for AI coding agents. Secures Copilot, Claude Code, Cursor, Windsurf, and any MCP-compatible agent.
Author-email: SecureMind <founders@securemind.live>
License: Proprietary
Project-URL: Homepage, https://securemind.live
Project-URL: Documentation, https://secure-mind-live.github.io/agnostic-security-site/
Project-URL: Repository, https://github.com/secure-mind-live/securityagent-core
Project-URL: Issues, https://github.com/secure-mind-live/securityagent-core/issues
Keywords: security,dlp,ai-agents,llm,copilot,claude-code,cursor,mcp,pii,credentials
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: watchdog
Requires-Dist: psutil
Requires-Dist: pydantic>=2.0
Requires-Dist: pypdf
Requires-Dist: openpyxl
Requires-Dist: python-docx
Requires-Dist: pyyaml
Provides-Extra: ml
Requires-Dist: sentence-transformers; extra == "ml"
Requires-Dist: scikit-learn; extra == "ml"
Requires-Dist: joblib; extra == "ml"
Requires-Dist: numpy; extra == "ml"
Provides-Extra: cloud
Requires-Dist: boto3; extra == "cloud"
Requires-Dist: PyJWT; extra == "cloud"
Requires-Dist: cryptography; extra == "cloud"
Provides-Extra: llm
Requires-Dist: ollama; extra == "llm"
Provides-Extra: ocr
Requires-Dist: PyMuPDF; extra == "ocr"
Requires-Dist: pytesseract; extra == "ocr"
Requires-Dist: Pillow; extra == "ocr"
Provides-Extra: pdf
Requires-Dist: fpdf2; extra == "pdf"
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Requires-Dist: moto; extra == "dev"
Provides-Extra: all
Requires-Dist: securityagent-core[cloud,llm,ml,ocr,pdf]; extra == "all"
Dynamic: license-file

# securityagent-core

The DLP engine behind [AgnosticSecurity](https://github.com/secure-mind-live/AgnosticSecurity) -- the firewall for AI coding agents.

**v4.60.0** | 1,235 tests | 242 detection patterns | 19 layers | 64/64 attack categories | 65/65 compliance | 40 languages

## Quick Start

```bash
pip install securityagent-core
as-init
```

`as-init` auto-detects your AI tools and configures protections. Supports:
**Claude Code** | **Copilot** | **Cursor** | **Windsurf** | **Aider** | **Continue** | **Tabnine** | **Codeium**

## What's Inside

| Package | What It Does |
|---------|-------------|
| `endpoint_agent/` | **DLP engine** -- file blocking (60+ path patterns), confidence-scored content scanning (PII, credentials, semantic disclosure) with structural validators (Luhn, SSA, entropy), data flow taint tracking (hash/n-gram/substring), tool call argument scanning (MCP/function DLP), behavioral monitoring, honeypot traps. Notebook-aware `.ipynb` + PDF extraction (PyMuPDF/Tesseract/pypdf). Image OCR via Tesseract + QR/barcode decode. |
| `skills/` | **MCP server** (9 tools) -- `secure_read`, `secure_write`, `secure_exec`, `analyze_prompt`, `scan_output`, `check_policy`, `get_session_policy`, `audit_log`, `scan_code`. Works with any MCP-compatible client. |
| `policy/` | **Policy engine** -- per-session least privilege, behavioral chain detection (11 attack patterns), audit trail with agent attribution. Obsidian vault integration for cross-session policy context. |
| `plugin.py` | **CLI entry point** -- `validate_exec()`, `validate_prompt()`, `validate_output()` pure functions. |

## Key Features

### Exec Guard (60+ rules)
Blocks dangerous commands before execution. High-confidence rules (env var dumps, encoded exfil) block immediately. Low-confidence rules go through a 4-tier decision: domain allowlist, localhost check, payload scan, LLM verification.

### Prompt Scanner (10 decode layers)
Catches PII and credentials even when obfuscated: direct regex, base64, hex escapes, ROT13, unicode escapes, URL percent-encoding, zero-width character stripping, reversed text, word-to-number with leetspeak, partial credential completion. Plus digit fragment reassembly and low-sensitivity PII escalation.

### Terminal Guard
Traces process ancestry -- if a parent process is an AI agent and a child process touches sensitive files, the operation is blocked. Priority-based cadence scanning.

### Code Fingerprint Guard
Registers proprietary code via n-gram fingerprinting. Detects similar code in prompts even with renamed variables (Jaccard similarity). Locality-aware thresholds.

### Data Flow Taint Tracking
Tags sensitive data at ingress (file read, prompt, tool result). Detects at egress via SHA-256 hash, n-gram Jaccard similarity, and substring matching. Cross-session persistence (24h TTL).

## Install

```bash
# From PyPI
pip install securityagent-core

# From source
pip install git+https://github.com/secure-mind-live/securityagent-core.git

# With optional dependencies
pip install "securityagent-core[cloud]"   # Cloud LLM providers (Anthropic, OpenAI)
pip install "securityagent-core[llm]"     # Local LLM (Ollama)
pip install "securityagent-core[dev]"     # Test dependencies
```

## Usage

### Python SDK

```python
from skills.adapters.python_sdk import SecurityAgentSDK

sdk = SecurityAgentSDK(agent_id="my-agent", agent_type="langchain")

result = sdk.secure_read("/path/to/file")       # DLP-gated file read
result = sdk.secure_exec("ls -la")              # Command validation
result = sdk.analyze_prompt("Get all SSNs")     # Prompt intent analysis
```

### MCP Server

```bash
python -m skills.adapters.mcp_server
```

Any MCP-compatible client (Claude Code, Copilot, Cursor, custom agents) connects via stdio JSON-RPC.

### CLI

```bash
python -m plugin ~/.env                                    # File read gate
python -m plugin --exec "cat ~/.env"                       # Exec validation
python -m plugin --prompt "Get all passwords"              # Prompt analysis
python -m plugin --mcp-server                              # MCP server mode
```

### Claude Code Integration

Add to `.claude/settings.json`:

```json
{
  "hooks": {
    "PreToolUse": [
      { "command": "python3 /path/to/hook_fast.py" }
    ]
  }
}
```

Or run `as-init` -- it configures this automatically.

## Tests

```bash
pip install -e ".[dev]"
pytest                      # Unit tests
python3 scripts/smoke_test.py   # 31 integration tests
```

Full suite: **1,235 tests across 32 suites** -- see [AgnosticSecurity](https://github.com/secure-mind-live/AgnosticSecurity) for the complete test runner.

## Numbers

| Metric | Value |
|--------|-------|
| Detection patterns | 242 |
| Detection layers | 19 (tiered: T0/T1/T2) |
| Attack categories | 64/64 (100%) |
| Compliance controls | 65/65 -- OWASP, NIST, MITRE, CSA |
| HarmBench ASR | Sub-3% |
| False positive rate | 0.99% |
| Languages | 40 |

## License

Proprietary. See [LICENSE](LICENSE).
