Metadata-Version: 2.4
Name: safeai-sdk
Version: 0.9.1
Summary: Framework-agnostic runtime boundary enforcement for AI systems
Author: SafeAI Contributors
License-Expression: Apache-2.0
Project-URL: Homepage, https://enendufrankc.github.io/safeai/
Project-URL: Repository, https://github.com/enendufrankc/safeai
Project-URL: Documentation, https://enendufrankc.github.io/safeai/
Project-URL: Bug Tracker, https://github.com/enendufrankc/safeai/issues
Keywords: ai-safety,guardrails,llm,agent-security,policy-engine
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Topic :: Security
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click<9,>=8.1
Requires-Dist: pydantic<3,>=2.7
Requires-Dist: pydantic-settings<3,>=2.2
Requires-Dist: PyYAML<7,>=6.0
Requires-Dist: jsonschema<5,>=4.22
Requires-Dist: structlog<26,>=24
Requires-Dist: fastapi<1,>=0.110
Requires-Dist: uvicorn<1,>=0.29
Requires-Dist: cryptography<47,>=42
Requires-Dist: httpx<1,>=0.27
Requires-Dist: rich<15,>=13.7
Requires-Dist: questionary<3,>=2.0
Provides-Extra: dev
Requires-Dist: pytest<10,>=8.0; extra == "dev"
Requires-Dist: pytest-benchmark<6,>=4.0; extra == "dev"
Requires-Dist: pytest-cov<7,>=5.0; extra == "dev"
Requires-Dist: ruff<1,>=0.4; extra == "dev"
Requires-Dist: mypy<2,>=1.9; extra == "dev"
Requires-Dist: pip-audit<3,>=2.7; extra == "dev"
Requires-Dist: types-PyYAML<7,>=6.0; extra == "dev"
Provides-Extra: vault
Requires-Dist: hvac<3,>=2.3; extra == "vault"
Provides-Extra: aws
Requires-Dist: boto3<2,>=1.34; extra == "aws"
Provides-Extra: mcp
Requires-Dist: mcp<2,>=1.0; extra == "mcp"
Provides-Extra: all
Requires-Dist: hvac<3,>=2.3; extra == "all"
Requires-Dist: boto3<2,>=1.34; extra == "all"
Requires-Dist: mcp<2,>=1.0; extra == "all"
Requires-Dist: uvicorn[standard]<1,>=0.27; extra == "all"
Provides-Extra: docs
Requires-Dist: mkdocs<2,>=1.6; extra == "docs"
Requires-Dist: mkdocs-material<10,>=9.5; extra == "docs"
Requires-Dist: mkdocstrings[python]<1,>=0.24; extra == "docs"
Requires-Dist: mkdocs-minify-plugin<1,>=0.8; extra == "docs"
Dynamic: license-file

<!-- prettier-ignore -->
<div align="center">

<img src="https://raw.githubusercontent.com/enendufrankc/safeai/main/docs/assets/banner.png" alt="SafeAI Banner" width="100%" />

# SafeAI

**Your AI agents are powerful. Are they safe?**

[![Build Status](https://img.shields.io/github/actions/workflow/status/enendufrankc/safeai/quality.yml?style=flat-square&label=Build)](https://github.com/enendufrankc/safeai/actions)
[![PyPI](https://img.shields.io/pypi/v/safeai-sdk?style=flat-square)](https://pypi.org/project/safeai-sdk/)
![Python](https://img.shields.io/badge/Python->=3.10-3776ab?style=flat-square&logo=python&logoColor=white)
[![Documentation](https://img.shields.io/badge/Docs-enendufrankc.github.io-00e5c8?style=flat-square)](https://enendufrankc.github.io/safeai/)
[![License](https://img.shields.io/badge/License-Apache--2.0-green?style=flat-square)](LICENSE)

[Why SafeAI](#the-problem) · [Quick Start](#quick-start) · [Features](#what-safeai-does) · [Integrations](#works-with-everything) · [Docs](https://enendufrankc.github.io/safeai/)

</div>

---

## The Problem

AI agents are shipping to production with **zero runtime security**. They can leak API keys in prompts, expose customer PII in responses, call unauthorized tools, and execute dangerous commands — and nobody finds out until the incident report.

Model safety training alone doesn't prevent these failures. You need enforcement at runtime, at the boundaries where data actually moves.

## The Solution

**SafeAI is the runtime security layer that sits between your AI agents and the outside world.** It intercepts every prompt, tool call, and model response — blocking secrets, redacting PII, enforcing policies, and logging everything to an immutable audit trail.

Two lines to get started. Zero changes to your existing code.

```python
from safeai import SafeAI

ai = SafeAI.quickstart()

# Block secrets before they reach any LLM
scan = ai.scan_input("Summarize this: token=sk-ABCDEF1234567890ABCDEF")
# => BLOCKED — secret detected, never reaches the model

# Redact PII from model responses before your users see them
guard = ai.guard_output("Contact alice@example.com or call 555-123-4567")
print(guard.safe_output)
# => "Contact [REDACTED] or call [REDACTED]"
```

> Works with OpenAI, Anthropic, Google, LangChain, CrewAI, AutoGen, Claude Code, Cursor, and any HTTP-based AI stack.

## How It Works

SafeAI enforces security at three runtime boundaries — the exact points where incidents happen:

```
                    ┌──────────────────────────────────┐
 User / Agent  ───▶ │  INPUT BOUNDARY   (scan_input)   │ ───▶ AI Provider
                    │  ACTION BOUNDARY  (intercept)    │      (OpenAI, Gemini,
 AI Provider   ◀─── │  OUTPUT BOUNDARY  (guard_output) │ ◀───  Claude, etc.)
                    └──────────────────────────────────┘
                               SafeAI Runtime
```

| Boundary | What it stops |
|:---|:---|
| **Input** | Secrets, credentials, and sensitive data in prompts before they reach the model |
| **Action** | Unauthorized tool calls, dangerous commands (`rm -rf /`, `DROP TABLE`), and cross-agent messaging violations |
| **Output** | PII, internal data, and unsafe content in model responses before they reach users |

Every decision is logged. Every action is auditable. No exceptions.

## Quick Start

### Install

```bash
pip install safeai-sdk
```

With extras for your stack:

```bash
pip install "safeai-sdk[vault]"   # HashiCorp Vault backend
pip install "safeai-sdk[aws]"     # AWS Secrets Manager backend
pip install "safeai-sdk[mcp]"     # MCP server for coding agents
pip install "safeai-sdk[all]"     # Everything
```

### Scaffold a full project

```bash
safeai init --path .
```

This generates `safeai.yaml`, policies, contracts, agent identities, plugins, and alert rules — ready for production. Then:

```python
ai = SafeAI.from_config("safeai.yaml")
```

### Deploy as a sidecar proxy

Protect any AI stack without changing a single line of application code:

```bash
safeai serve --mode sidecar --host 127.0.0.1 --port 8910 --config safeai.yaml
```

```bash
curl http://127.0.0.1:8910/v1/health    # Health check
curl -s -X POST http://127.0.0.1:8910/v1/scan/input \
  -H "content-type: application/json" \
  -d '{"text":"hello world","agent_id":"default-agent"}'
```

### AI-powered auto-configuration

Let SafeAI's intelligence layer analyze your codebase and generate tailored security policies:

```bash
safeai intelligence auto-config --apply
```

## What SafeAI Does

### 🔒 Detection & Prevention
| Capability | Description |
|:---|:---|
| **Secret Detection** | Blocks API keys, tokens, and credentials before they reach any LLM |
| **PII Protection** | Auto-redacts emails, phone numbers, SSNs, credit cards, and more |
| **Content Moderation** | 80+ detectors for toxicity, prompt injection, jailbreaks — all local, no external APIs |
| **Dangerous Commands** | Stops `rm -rf /`, `DROP TABLE`, fork bombs, pipe-to-shell, force pushes |

### 🛡️ Policy & Control
| Capability | Description |
|:---|:---|
| **Policy Engine** | Priority-based YAML rules with tag hierarchies, hot reload, and boundary-specific matching |
| **Tool Contracts** | Declare what each tool can accept/emit — undeclared tools are denied by default |
| **Agent Identity** | Bind agents to specific tools and clearance levels for zero-trust enforcement |
| **Approval Workflows** | Human-in-the-loop gates for high-risk operations with TTL and dedup |

### 🏗️ Infrastructure
| Capability | Description |
|:---|:---|
| **Encrypted Memory** | Schema-enforced agent memory with field-level encryption and auto-expiry |
| **Capability Tokens** | Scoped, time-limited tokens for secret access — agents never see raw credentials |
| **Audit Trail** | Append-only logs with context hashes, filterable by agent, tool, session, and time |
| **Multi-Provider Routing** | Priority, cost, latency, and round-robin strategies with circuit-breaker failover |

### 🚀 Operations & Scale
| Capability | Description |
|:---|:---|
| **Dashboard** | Web UI for incidents, approvals, compliance summaries, and tenant/RBAC controls |
| **Alerting** | File, webhook, Slack, email, PagerDuty, and Opsgenie channels with Prometheus metrics |
| **Skills System** | Install pre-built packages — GDPR, HIPAA, PCI-DSS, prompt injection shield — in one command |
| **Intelligence Layer** | 5 AI advisory agents for auto-config, policy recs, incident explanation, and compliance mapping |
| **Cost Governance** | Track token usage, enforce budgets with hard blocks, extract costs from provider responses |

## Works With Everything

| AI Providers | Agent Frameworks | Coding Agents | Deployment |
|:---|:---|:---|:---|
| OpenAI | LangChain | Claude Code | Python SDK |
| Anthropic Claude | CrewAI | Cursor | REST API (sidecar) |
| Google Gemini | AutoGen | Copilot | Gateway proxy |
| Ollama | Claude ADK | Any MCP client | MCP server |
| Any HTTP API | Google ADK | | CLI hooks |

```python
# Example: Wrap any LangChain tool in 3 lines
from safeai import SafeAI
from safeai.middleware.langchain import wrap_langchain_tool

ai = SafeAI.from_config("safeai.yaml")
safe_tool = wrap_langchain_tool(ai, my_tool, agent_id="default-agent")
```

## CLI at a Glance

```bash
safeai init --path .                          # Scaffold config and policies
safeai serve --mode sidecar --port 8910       # Start the proxy server
safeai setup claude-code --config safeai.yaml # Install into Claude Code
safeai setup cursor --config safeai.yaml      # Install into Cursor
safeai mcp --config safeai.yaml               # Start MCP server
safeai intelligence auto-config --path .      # AI-powered auto-configuration
safeai skills add prompt-injection-shield     # Install a skill package
safeai scan --boundary input --input "text"   # Scan from the command line
safeai approvals list --status pending        # Manage approval queues
safeai observe agents                         # Agent observability
```

> [!TIP]
> Run `safeai --help` or see the full [CLI reference](https://enendufrankc.github.io/safeai/cli/) for all commands.

## Extend with Plugins

Drop custom detectors, adapters, and policy templates into `plugins/`:

```python
def safeai_detectors():
    return [(r"my-pattern", "custom.tag", "my_detector")]

def safeai_policy_templates():
    return [{"name": "my-template", "template": {"version": "v1alpha1", "policies": []}}]
```

Built-in template packs: `finance`, `healthcare`, `support`.

## Documentation

| Resource | Link |
|:---|:---|
| Getting started | [Installation](https://enendufrankc.github.io/safeai/getting-started/installation/) · [Quickstart](https://enendufrankc.github.io/safeai/getting-started/quickstart/) · [Configuration](https://enendufrankc.github.io/safeai/getting-started/configuration/) |
| Guides | [Policy Engine](https://enendufrankc.github.io/safeai/guides/policy-engine/) · [Tool Contracts](https://enendufrankc.github.io/safeai/guides/tool-contracts/) · [Agent Identity](https://enendufrankc.github.io/safeai/guides/agent-identity/) · [Audit Logging](https://enendufrankc.github.io/safeai/guides/audit-logging/) |
| Integrations | [LangChain](https://enendufrankc.github.io/safeai/integrations/langchain/) · [CrewAI](https://enendufrankc.github.io/safeai/integrations/crewai/) · [AutoGen](https://enendufrankc.github.io/safeai/integrations/autogen/) · [Coding Agents](https://enendufrankc.github.io/safeai/integrations/coding-agents/) |
| Reference | [CLI](https://enendufrankc.github.io/safeai/cli/) · [API](https://enendufrankc.github.io/safeai/reference/safeai/) · [Architecture](https://enendufrankc.github.io/safeai/project/architecture/) |

## Local Development

```bash
git clone https://github.com/enendufrankc/safeai.git
cd safeai
pip install -e ".[dev,all]"
```

Run the quality gates:

```bash
ruff check safeai tests        # Lint
mypy safeai                    # Type check
python -m pytest tests/ -v     # Test
```
