Skip to main content

Framework-agnostic runtime boundary enforcement for AI systems

Project description

SafeAI Banner

SECURE. INTELLIGENT. TRUSTED.

Build Release PyPI License Stars

The runtime security layer for AI agents.
Block secrets. Redact PII. Enforce policies. Control tool calls. Require approvals.
Works with any model stack, framework, and deployment style.


Table of Contents

What SafeAI Is

SafeAI enforces policy at three runtime boundaries:

  • input: before user or agent data reaches a model.
  • action: before and after tool execution, and during agent-to-agent messaging.
  • output: before model output is returned or forwarded.

That model keeps policy decisions close to execution, where incidents actually happen.

                    +----------------------------------+
 User / Agent  ---> |  INPUT BOUNDARY   (scan_input)  | ---> AI Provider
                    |  ACTION BOUNDARY  (intercept)   |      (OpenAI, Gemini,
 AI Provider   <--- |  OUTPUT BOUNDARY  (guard_output)| <---  Claude, etc.)
                    +----------------------------------+
                              SafeAI Runtime

Current status: Sprint 0 through Phase 7 complete, with v0.7.0 release gate passed.

Capability Overview

SafeAI is intentionally broad. This is the complete capability set currently implemented:

Area Capabilities
Detection and classification Built-in detectors for secrets and personal data (email, phone, ssn, credit_card, api_key) with hierarchical tags
Policy engine Priority-based first-match rules, YAML policies, schema validation, hot reload, fallback output templates
Input and output controls Prompt scanning (scan_input), response guarding (guard_output), redaction/block/allow enforcement
Structured and file scanning Nested payload scanning (scan_structured_input) and file scanning (scan_file_input) for JSON and text
Tool boundary enforcement Request contract checks, response filtering, undeclared tool denial, per-field stripping
Agent identity Agent registry, tool binding, clearance-tag enforcement
Agent messaging Source/destination-aware, policy-gated agent-to-agent message interception
Approvals require_approval runtime gate with persistent queue and explicit approve/deny flow
Secrets access Capability-token TTL/scope/session binding, secret manager abstraction, Env/Vault/AWS backends
Memory security Schema-enforced memory controller, encrypted handle storage, retention and purge workflow
Auditability Append-only JSON logs, rich query filters (boundary/action/agent/tool/tag/session/time/metadata), context hashes and event IDs
Proxy runtime Sidecar and gateway modes, upstream forwarding, health endpoint, policy reload endpoint
Observability Prometheus-style metrics (/v1/metrics) with request/decision counters and latency buckets
Integrations LangChain, CrewAI, AutoGen, Claude ADK, Google ADK, coding-agent hooks, MCP server
Extensibility Plugin loader for detectors/adapters/templates, built-in policy template catalog (finance, healthcare, support)
Operations UI Web dashboard (/dashboard) for incidents, approvals, compliance summaries, tenant/RBAC controls, alerts
Intelligence layer 5 AI advisory agents: auto-config, policy recommender, incident explainer, compliance mapper, integration generator. BYOM (Bring Your Own Model), metadata-only, human-approved staging

Install

uv pip install safeai-sdk

Or with pip:

pip install safeai-sdk

Optional extras:

uv pip install "safeai-sdk[vault]"   # HashiCorp Vault backend
uv pip install "safeai-sdk[aws]"     # AWS Secrets Manager backend
uv pip install "safeai-sdk[mcp]"     # MCP server support
uv pip install "safeai-sdk[all]"     # Vault + AWS + MCP
uv pip install "safeai-sdk[dev]"     # local development tooling

Quick Start (SDK)

For fast adoption with no config files:

from safeai import SafeAI

ai = SafeAI.quickstart()

Then enforce both ends of the model call:

# Input boundary
scan = ai.scan_input("Summarize this: token=sk-ABCDEF1234567890ABCDEF")
print(scan.decision.action, scan.decision.reason)

# Output boundary
guard = ai.guard_output("Contact alice@example.com")
print(guard.safe_output)

Structured payload example:

payload = {"user": {"email": "alice@example.com"}, "note": "hello world"}
result = ai.scan_structured_input(payload, agent_id="default-agent")
print(result.decision.action)
print(result.filtered)

Scaffold a Full Config Project

When you need full policy and runtime control:

safeai init --path .

This scaffolds:

  • safeai.yaml
  • policies/default.yaml
  • contracts/example.yaml
  • schemas/memory.yaml
  • agents/default.yaml
  • plugins/example.py
  • tenants/policy-sets.yaml
  • alerts/default.yaml

Use config mode via:

from safeai import SafeAI

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

Run as a Proxy API

Start the proxy:

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

Health check:

curl http://127.0.0.1:8910/v1/health

Hello world scan:

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"}'

Core HTTP endpoints:

  • GET /v1/health
  • GET /v1/metrics
  • POST /v1/scan/input
  • POST /v1/scan/structured
  • POST /v1/scan/file
  • POST /v1/guard/output
  • POST /v1/intercept/tool
  • POST /v1/intercept/agent-message
  • POST /v1/memory/write
  • POST /v1/memory/read
  • POST /v1/memory/resolve-handle
  • POST /v1/memory/purge-expired
  • POST /v1/audit/query
  • POST /v1/policies/reload
  • GET /v1/plugins
  • GET /v1/policies/templates
  • GET /v1/policies/templates/{template_name}
  • POST /v1/proxy/forward
  • GET /v1/intelligence/status
  • POST /v1/intelligence/explain
  • POST /v1/intelligence/recommend
  • POST /v1/intelligence/compliance
  • GET /dashboard

CLI Commands

Daily commands you will actually use:

safeai init --path .
safeai validate --config safeai.yaml
safeai scan --boundary input --input "hello world"
safeai logs --tail 20 --json-output
safeai serve --mode sidecar --port 8910

safeai approvals list --status pending
safeai approvals approve <request_id> --approver security-lead
safeai approvals deny <request_id> --approver security-lead --note "policy mismatch"

safeai templates list
safeai templates show --name healthcare --format yaml

safeai setup claude-code --config safeai.yaml --path .
safeai setup cursor --config safeai.yaml --path .
safeai setup generic --config safeai.yaml

safeai hook --config safeai.yaml
safeai mcp --config safeai.yaml

safeai intelligence auto-config --path . --output-dir .safeai-generated
safeai intelligence recommend --since 7d
safeai intelligence explain <event_id>
safeai intelligence compliance --framework hipaa
safeai intelligence integrate --target langchain --path .

Framework and Agent Integrations

Built-in adapters:

  • LangChain
  • CrewAI
  • AutoGen
  • Claude ADK
  • Google ADK

Coding-agent integration:

  • universal hook adapter (safeai hook)
  • installer commands for Claude Code and Cursor (safeai setup ...)
  • MCP server (safeai mcp) for MCP-compatible clients

Quick adapter example:

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")

Plugins and Policy Templates

Phase 6 added extensibility as first-class behavior.

Plugin model:

  • load plugin modules from plugins/*.py (configurable in safeai.yaml)
  • extend detector patterns
  • register adapters
  • contribute policy templates

Template catalog:

  • built-in packs: finance, healthcare, support
  • list with safeai templates list
  • inspect with safeai templates show --name <template>
  • proxy discovery endpoints via /v1/policies/templates*

Minimal plugin shape:

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

def safeai_adapters():
    return {
        "my-adapter": lambda safeai: object(),
    }

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

Dashboard and Enterprise Operations

SafeAI includes a dashboard surface for security operations:

  • incidents and policy events
  • approval queue workflow
  • compliance report summaries
  • tenant-scoped policy sets
  • RBAC checks
  • alert rule evaluation and alert logs

Run the proxy and open /dashboard in your browser.

Documentation Map

Start here:

Guides:

Integrations:

Reference:

Project and planning:

Notebooks:

Contributing, Security, and Governance

Core project policies:

Local Development

git clone https://github.com/enendufrankc/safeai.git
cd safeai
uv sync --extra dev --extra all

Or with pip:

pip install -e ".[dev,all]"

Quality gates used in CI:

uv run ruff check safeai tests
uv run mypy safeai
uv run python -m pytest tests/ -v

License

SafeAI is licensed under Apache 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safeai_sdk-0.8.1.tar.gz (147.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safeai_sdk-0.8.1-py3-none-any.whl (142.0 kB view details)

Uploaded Python 3

File details

Details for the file safeai_sdk-0.8.1.tar.gz.

File metadata

  • Download URL: safeai_sdk-0.8.1.tar.gz
  • Upload date:
  • Size: 147.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for safeai_sdk-0.8.1.tar.gz
Algorithm Hash digest
SHA256 ede061fe3a696896092e703602054c8bc06d62fc4efae52f631c79b9f3a54092
MD5 7bbee9447aaa94fb6d726e775ab5c0d9
BLAKE2b-256 f1cd495385f1ea69f0f2a6129b6253861e4de63411889a7efafe9289c2e619ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for safeai_sdk-0.8.1.tar.gz:

Publisher: publish.yml on enendufrankc/safeai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file safeai_sdk-0.8.1-py3-none-any.whl.

File metadata

  • Download URL: safeai_sdk-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 142.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for safeai_sdk-0.8.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1adec9a9385766f3dc2cb0ba38055c908d980523670ac83410a02b3a7218b76e
MD5 086b58d6cf500e67a2c52467b6767eaf
BLAKE2b-256 07bcbdc2d434074bfd5ed1fa83cba4967d90d78e4bb2629c2c8ace374a30429b

See more details on using hashes here.

Provenance

The following attestation bundles were made for safeai_sdk-0.8.1-py3-none-any.whl:

Publisher: publish.yml on enendufrankc/safeai

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page