Skip to content

CLI Reference

SafeAI ships a single safeai command with subcommands for scanning, serving, auditing, and managing your safety configuration.

uv pip install safeai
safeai --help

safeai init

Scaffold SafeAI configuration files and interactively configure the intelligence layer.

safeai init [--path DIR] [--non-interactive]

Flags

Flag Type Default Description
--path path . Project directory to initialize
--non-interactive flag off Skip interactive prompts (scaffold files only)

What it does

  1. Scaffolds config files — creates default policies, contracts, schemas, and agent identities
  2. Interactive intelligence setup — walks you through choosing an AI backend (Ollama, OpenAI, Anthropic, or custom) and writes the configuration to safeai.yaml

This creates:

Path Purpose
safeai.yaml Main configuration file (with intelligence config if enabled)
policies/ Policy rule files
contracts/ Tool contract definitions
schemas/ Memory and state schemas
agents/ Agent identity documents
plugins/example.py Plugin starter template
tenants/ Multi-tenant policy sets
alerts/ Alert rule definitions

Example

$ safeai init
SafeAI initialized
  created: safeai.yaml
  created: policies/default.yaml
  ...

Intelligence Layer Setup
SafeAI can use an AI backend to auto-generate policies,
explain incidents, and recommend improvements.

Enable the intelligence layer? [Y/n]: Y

Choose your AI backend:
  1. Ollama (local, free — no API key needed)
  2. OpenAI
  3. Anthropic
  4. Google Gemini
  5. Mistral
  6. Groq
  7. Azure OpenAI
  8. Cohere
  9. Together AI
  10. Fireworks AI
  11. DeepSeek
  12. Other (any OpenAI-compatible endpoint)

Select provider [1]: 1

Intelligence layer configured!
  provider: ollama
  model:    llama3.2

Tip

Run safeai init at the root of every repository that uses AI agents. The interactive setup means you never need to edit YAML by hand.


safeai scan

Scan text through the SafeAI boundary engine and return the enforcement decision.

safeai scan --boundary <BOUNDARY> --input <TEXT>

Flags

Flag Type Required Description
--boundary input \| output Yes Which boundary to evaluate
--input string Yes The text payload to scan

Examples

# Scan an input prompt for secrets and PII
safeai scan --boundary input --input "My SSN is 123-45-6789"

# Scan model output before returning to a user
safeai scan --boundary output --input "Here is the API key: sk-abc123..."

The command prints the enforcement result (allow, block, redact, or flag) along with any matched detections.


safeai validate

Validate your SafeAI configuration files: policies, schemas, memory definitions, and agent identity documents.

safeai validate --config <PATH>

Flags

Flag Type Default Description
--config path .safeai/safeai.yaml Path to the SafeAI config file

Examples

# Validate the default config
safeai validate

# Validate a specific config file
safeai validate --config /etc/safeai/production.yaml

Output includes counts of policies loaded, memory schemas validated, and agent identity documents found.

Warning

Always run safeai validate in CI before deploying configuration changes. Invalid policies can cause unexpected enforcement behavior at runtime.


safeai logs

Query the audit log for boundary enforcement decisions.

safeai logs [FLAGS]

Flags

Flag Type Default Description
--tail int 20 Number of recent events to return
--boundary input \| output \| action all Filter by boundary type
--action allow \| block \| redact \| flag all Filter by enforcement action
--agent string all Filter by agent name
--last duration all time Time window (e.g., 1h, 30m, 7d)
--text-output flag off Plain-text table output (default is JSON)
--detail string -- Show full detail for a specific event ID

Examples

# Last 20 events, JSON output
safeai logs

# Last 10 block decisions in the past hour, plain text
safeai logs --tail 10 --action block --last 1h --text-output

# Filter by agent and boundary
safeai logs --agent research-agent --boundary input --tail 50

# Full detail for a specific event
safeai logs --detail evt_a1b2c3d4

Info

Audit events include event_id, context_hash, session/source/destination IDs, matched policy, detection tags, and the enforcement action taken.


safeai serve

Start the SafeAI proxy server in sidecar or gateway mode.

safeai serve [FLAGS]

Flags

Flag Type Default Description
--mode sidecar \| gateway sidecar Proxy operating mode
--port int 8000 Port to listen on
--config path .safeai/safeai.yaml Path to the SafeAI config file

Modes

  • Sidecar -- Runs alongside a single agent process. All traffic from that agent passes through SafeAI for scanning and enforcement.
  • Gateway -- Sits between multiple agents and upstream services. Requires source/destination agent context on each request for multi-agent enforcement.

Examples

# Start a sidecar on the default port
safeai serve

# Start a gateway on port 9000 with a custom config
safeai serve --mode gateway --port 9000 --config /etc/safeai/prod.yaml

Note

The proxy exposes a full REST API surface including /v1/scan/input, /v1/scan/output, /v1/tools/intercept, /v1/memory/*, /v1/audit/logs, /v1/metrics, and more. See the Proxy / Sidecar guide for full endpoint documentation.


safeai hook

Universal coding-agent hook. This command reads a pending tool call from stdin, enforces SafeAI policies, and returns the decision.

safeai hook

The hook is designed to be called by coding agents (Claude Code, Cursor, etc.) as a pre-execution gate. It:

  1. Reads the tool name and arguments from stdin (JSON).
  2. Loads the agent profile for the calling agent.
  3. Evaluates the action against configured policies and tool contracts.
  4. Returns allow, block, or require_approval with an explanation.

Tip

You do not need to invoke safeai hook manually. Use safeai setup to install it automatically for your coding agent.


safeai setup

Install SafeAI hooks into a supported coding agent.

safeai setup <AGENT>

Supported agents

Agent Command
Claude Code safeai setup claude-code
Cursor safeai setup cursor

Examples

# Install the hook for Claude Code
safeai setup claude-code

# Install the hook for Cursor
safeai setup cursor

The installer registers safeai hook as the pre-execution callback in the agent's configuration, so every tool invocation is evaluated by SafeAI before execution.


safeai approvals

Manage the human-in-the-loop approval workflow for actions that require explicit authorization.

safeai approvals <SUBCOMMAND> [FLAGS]

Subcommands

Subcommand Description
list Show pending approval requests
approve Approve a pending request by ID
deny Deny a pending request by ID

Examples

# List all pending approvals
safeai approvals list

# Approve a specific request
safeai approvals approve req_abc123

# Deny a specific request with a reason
safeai approvals deny req_def456 --reason "Outside permitted scope"

How approvals work

When a policy rule sets action: require_approval, the tool call is paused and an approval request is created. The agent cannot proceed until a human operator approves or denies the request via this command or the dashboard UI.


safeai templates

Browse and inspect the built-in policy template catalog.

safeai templates <SUBCOMMAND>

Subcommands

Subcommand Description
list List all available policy templates
show TEMPLATE Display the full content of a named template

Examples

# List all templates (built-in + plugins)
safeai templates list

# Show the healthcare template pack
safeai templates show healthcare

# Show the finance template
safeai templates show finance

Built-in template packs include finance, healthcare, and support. Plugin-provided templates are discovered automatically when plugins are loaded.


safeai mcp

Start the SafeAI MCP (Model Context Protocol) server for tool-based integration with MCP-compatible clients.

safeai mcp

The MCP server exposes SafeAI's scanning, policy evaluation, and audit capabilities as MCP tools, allowing MCP-compatible agents and IDEs to call SafeAI directly through the protocol.

Note

The MCP server uses stdio transport by default and is intended to be launched by an MCP client, not run standalone.


safeai intelligence

AI advisory commands for configuration generation, policy recommendations, incident explanation, compliance mapping, and integration code generation.

safeai intelligence <SUBCOMMAND> [FLAGS]

Subcommands

Subcommand Description
auto-config Generate SafeAI configuration from project structure
recommend Suggest policy improvements from audit data
explain Classify and explain a security incident
compliance Generate compliance policy sets
integrate Generate framework-specific integration code

auto-config

safeai intelligence auto-config [--path .] [--framework langchain] [--output-dir .safeai-generated] [--apply] [--config safeai.yaml]
Flag Type Default Description
--path path . Project path to analyze
--framework string auto-detect Framework hint (e.g., langchain, crewai)
--output-dir path .safeai-generated Directory for generated files
--apply flag off Copy generated files to project root
--config path safeai.yaml Path to safeai.yaml

recommend

safeai intelligence recommend [--since 7d] [--output-dir .safeai-generated] [--config safeai.yaml]
Flag Type Default Description
--since duration 7d Time window for audit analysis
--output-dir path .safeai-generated Directory for generated files
--config path safeai.yaml Path to safeai.yaml

explain

safeai intelligence explain <EVENT_ID> [--config safeai.yaml]

Takes a single event ID as argument and prints the classification and explanation.

compliance

safeai intelligence compliance --framework <FRAMEWORK> [--output-dir .safeai-generated] [--config safeai.yaml]
Flag Type Required Description
--framework hipaa\|pci-dss\|soc2\|gdpr Yes Compliance framework to map
--output-dir path No Directory for generated files
--config path No Path to safeai.yaml

integrate

safeai intelligence integrate --target <FRAMEWORK> [--path .] [--output-dir .safeai-generated] [--config safeai.yaml]
Flag Type Required Description
--target string Yes Target framework (langchain, crewai, autogen, etc.)
--path path No Project path
--output-dir path No Directory for generated files
--config path No Path to safeai.yaml

Requires AI backend

All intelligence commands require intelligence.enabled: true in safeai.yaml and a configured AI backend. See the Intelligence Layer guide for setup instructions.


safeai alerts

Manage alert channels for enforcement event notifications.

safeai alerts <SUBCOMMAND> [FLAGS]

Subcommands

Subcommand Description
add Register a new alert channel
list List configured alert channels
test Send a test alert to a channel

Examples

# Add a Slack webhook channel
safeai alerts add --channel slack --url https://hooks.slack.com/services/...

# Add a file-based alert log
safeai alerts add --channel file --path /var/log/safeai/alerts.json

# Add a generic webhook
safeai alerts add --channel webhook --url https://example.com/alerts

# List all configured channels
safeai alerts list

# Send a test alert
safeai alerts test --channel slack

safeai observe

Observe agent activity and session traces.

safeai observe <SUBCOMMAND>

Subcommands

Subcommand Description
agents Show agent activity timeline
sessions Show session traces

Examples

# View agent activity across all agents
safeai observe agents

# View session traces
safeai observe sessions

safeai skills

Manage installable SafeAI skill packages. Skills bundle policies, plugins, deployment scripts, and reference documentation into reusable packages.

safeai skills <SUBCOMMAND> [FLAGS]

Subcommands

Subcommand Description
list List installed skills
search Search the skills registry
add Install a skill by name
install Install a skill by name (alias for add)
remove Uninstall a skill

Examples

# List all installed skills
safeai skills list

# Search for skills by keyword
safeai skills search secret
safeai skills search gdpr

# Install a skill from the registry
safeai skills add prompt-injection-shield
safeai skills add gdpr-policies

# Remove an installed skill
safeai skills remove prompt-injection-shield

Available Skills

Skill Description
safeai Core SafeAI reference skill with policies and plugins
safeai-deploy Deployment automation scripts and observability references
langchain-adapter LangChain integration plugin
prompt-injection-shield Prompt injection detection plugin and policy
secrets-detector Extended secrets detection plugin
finance-policies PCI-DSS compliance policy pack
gdpr-policies GDPR compliance policy pack
healthcare-policies HIPAA compliance policy pack

Node.js installer

Skills can also be installed via the Node.js CLI: npx safeai add <skill-name>