Skip to main content

An AI coding agent you can actually trust - with built-in impact preview

Project description

๐Ÿ›ก๏ธ Safe Agent

Guardrails for AI code agents.

Safe Agent previews every file edit with impact-preview so AI helpers canโ€™t quietly ship risky changes. Drop it into CI or run locally and require approvals before writes.

pip install safe-agent-cli
safe-agent "add error handling to api.py" --dry-run

โœจ New in v0.4.0

  • ๐Ÿงญ Policy-as-code enforcement - Deterministic allow/deny/require-approval decisions before execution
  • ๐ŸŽ›๏ธ Policy presets - --policy-preset startup|fintech|games plus --list-policy-presets
  • ๐Ÿ•ต๏ธ Prompt injection scan surfaced - Preview shows scanner severity + reason IDs

Project Map

  • impact-preview (Agent Polis): the guardrail layer that previews and scores risky actions.
  • safe-agent-cli (this repo): a reference coding agent that uses impact-preview for approvals.
  • Roadmap: staged execution plan in ROADMAP.md.
  • Compatibility Matrix: version contract in docs/compatibility-matrix.md.
  • Monday Packet: current assignment bundle in docs/monday-assignment-packet.md.

The Problem

AI coding agents are powerful but dangerous:

  • Replit Agent deleted a production database
  • Cursor YOLO mode deleted an entire system
  • You can't see what's about to happen until it's too late

The Solution

Safe Agent previews every change before execution:

$ safe-agent "update database config to use production"

๐Ÿ“‹ Task: update database config to use production

๐Ÿ“ Planned Changes
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Action โ”‚ File            โ”‚ Description             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ MODIFY โ”‚ config/db.yaml  โ”‚ Update database URL     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Step 1/1

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Impact Preview โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Update database URL                          โ”‚
โ”‚                                              โ”‚
โ”‚ **File:** `config/db.yaml`                   โ”‚
โ”‚ **Action:** MODIFY                           โ”‚
โ”‚ **Risk:** ๐Ÿ”ด CRITICAL                        โ”‚
โ”‚ **Policy:** REQUIRE_APPROVAL [builtin]       โ”‚
โ”‚ **Scanner:** LOW                             โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Risk Factors:
  โš ๏ธ  Production pattern detected: production
  โš ๏ธ  Database configuration change

Diff:
- url: postgresql://localhost:5432/dev
+ url: postgresql://prod-server:5432/production

โš ๏ธ  CRITICAL RISK - Please review carefully!
Apply this change? [y/N]: 

Installation

pip install safe-agent-cli

Set your Anthropic API key:

export ANTHROPIC_API_KEY=your-key-here

Usage

Basic Usage

# Run a coding task
safe-agent "add input validation to user registration"

# Preview only (no execution)
safe-agent "refactor auth module" --dry-run

# Auto-approve low-risk changes
safe-agent "add docstrings" --auto-approve-low

CI / Non-interactive mode

Use --non-interactive to avoid prompts (auto-approves when policy allows; skips anything requiring approval). Combine with --fail-on-risk to fail the process if risky changes are proposed:

safe-agent "scan repository for risky config changes" --dry-run --non-interactive --fail-on-risk high

Policy (allow/deny/require approval)

By default Safe Agent enforces a built-in policy that:

  • denies obvious secret/key targets (e.g. .env, .ssh, .pem)
  • allows LOW/MEDIUM risk actions
  • requires approval for HIGH/CRITICAL risk actions

Override with a bundled preset:

safe-agent --list-policy-presets
safe-agent "update auth flow" --policy-preset fintech

Or load a policy file (JSON/YAML):

safe-agent "update auth flow" --policy ./policy.json

Interactive Mode

safe-agent --interactive

From File

safe-agent --file task.md

How It Works

  1. Plan - Claude analyzes your task and plans file changes
  2. Preview - Each change runs through impact-preview for risk analysis
  3. Approve - You see the diff and risk level before anything executes
  4. Execute - Only approved changes are applied

Enterprise & Compliance Features

Safe Agent now includes features for insurance partnerships, regulatory compliance, and enterprise deployments.

Audit Export for Insurance

Export complete audit trails for insurance underwriting and claims:

safe-agent "update production config" --audit-export audit.json

The audit export includes:

  • Complete task history with timestamps
  • Risk assessments for all operations
  • Approval/rejection records (human oversight)
  • Change execution status
  • Compliance flags for regulatory requirements

Perfect for working with AI liability insurance carriers like AIUC, Armilla AI, and Beazley.

See docs/insurance-integration.md for details on insurance partnerships and premium rate factors.

EU AI Act Compliance Mode

Enable strict compliance mode for EU AI Act requirements:

safe-agent "modify user data" --compliance-mode --audit-export audit.json

Compliance mode:

  • Disables all auto-approve features (Article 14: Human Oversight)
  • Requires explicit approval for every operation
  • Records all compliance flags in audit exports
  • Supports Article 12 (Record-Keeping) requirements

Ready for the August 2, 2026 enforcement deadline.

See docs/eu-ai-act-compliance.md for complete compliance guide and requirements mapping.

Incident Documentation

We maintain a comprehensive database of AI agent incidents to raise awareness and demonstrate prevention mechanisms:

Submit an incident report to help the community.

Options

Flag Description
--dry-run Preview changes without executing
--auto-approve-low Auto-approve low-risk changes
--non-interactive Run without prompts (CI-friendly)
--fail-on-risk Exit non-zero if any change meets/exceeds risk level
--policy Path to a policy file (JSON/YAML) for deterministic allow/deny/approval
--policy-preset Use a bundled policy preset (startup, fintech, games)
--list-policy-presets List available policy presets and exit
--interactive, -i Interactive mode
--file, -f Read task from file
--model Claude model to use (default: claude-sonnet-4-20250514)
--audit-export Export audit trail to JSON file (insurance/compliance)
--compliance-mode Enable strict compliance mode (disables auto-approve)

MCP Server (For Other AI Agents)

Safe Agent can be used as an MCP server, letting other AI agents delegate coding tasks safely.

# Start the MCP server
safe-agent-mcp

Claude Desktop Integration

Add to ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "safe-agent": {
      "command": "safe-agent-mcp"
    }
  }
}

Available MCP Tools

Tool Description Safety
run_coding_task Execute a coding task with preview ๐Ÿ”ด Destructive
preview_coding_task Preview changes without executing ๐ŸŸข Read-only
get_agent_status Check agent status and capabilities ๐ŸŸข Read-only

Moltbook Integration

Safe Agent is available as a Moltbook skill for AI agent networks.

See moltbook-skill.json for the skill definition.

Demo Producer

Set up a canned risky-edit scenario and print recording commands:

safe-agent-demo prepare  # creates a demo repo with config/db.yaml
cd /tmp/safe-agent-demo-*  # or your chosen path
safe-agent-demo record     # shows asciinema + GIF commands

By default the demo runs safe-agent --dry-run "switch database config to production" against the prepared repo.

Safe Agent demo

For AI Agents

If you're an AI agent wanting to use Safe Agent programmatically:

from safe_agent import SafeAgent

agent = SafeAgent(
    auto_approve_low_risk=True,      # Skip approval for low-risk changes
    dry_run=False,                   # Set True to preview only
    audit_export_path="audit.json",  # Export audit trail for compliance
    compliance_mode=False,           # Enable for EU AI Act compliance
)

result = await agent.run("add error handling to api.py")

For insurance and compliance use cases:

# EU AI Act compliant configuration
agent = SafeAgent(
    compliance_mode=True,              # Strict compliance mode
    audit_export_path="audit.json",    # Required for Article 12
    non_interactive=False,             # Human oversight required
)

Powered By

  • impact-preview - Impact analysis and diff generation
  • Claude - AI planning and code generation
  • Rich - Beautiful terminal output
  • MCP - Model Context Protocol for agent interoperability

Known Incidents

AI coding agents without proper safeguards have caused real damage. We document these incidents to raise awareness and demonstrate why preview-before-execute architecture matters.

Recent Incidents

Submit an Incident

Experienced an AI agent incident? Help the community by submitting an incident report.

Browse all documented incidents in docs/incident-reports/.

Marketing Helpers

A lightweight CLI to generate headline variants, channel-specific copy (HN, Twitter/X, LinkedIn), and README hero blocks:

safe-agent-marketing generate --audience "Teams running AI code agents in CI" \
  --hypothesis "Guardrail that blocks risky edits" --update-readme

This writes JSON/Markdown bundles to marketing/ and (optionally) refreshes the README hero block. Queue posts with:

safe-agent-marketing queue --slot 2026-02-05T15:00:00Z --slot 2026-02-05T20:00:00Z

Log traction daily:

safe-agent-marketing analytics --repo agent-polis/safe-agent --log experiments/experiments.csv

License

MIT License - see LICENSE for details.


Built by developers who want AI agents they can actually trust.

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

safe_agent_cli-0.4.0.tar.gz (238.6 kB view details)

Uploaded Source

Built Distribution

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

safe_agent_cli-0.4.0-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file safe_agent_cli-0.4.0.tar.gz.

File metadata

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

File hashes

Hashes for safe_agent_cli-0.4.0.tar.gz
Algorithm Hash digest
SHA256 66d1eaa37f60ac1058aecf92a8273888491e9b8169400ae2aa319661ee5b97db
MD5 b004ca007dc2dcdcfc32bf63e489217e
BLAKE2b-256 f8fdeb332d5c44ce52dfd5d446cd3daa5a3e5e66f8346d88b91ac222c791f404

See more details on using hashes here.

Provenance

The following attestation bundles were made for safe_agent_cli-0.4.0.tar.gz:

Publisher: release.yml on agent-polis/safe-agent

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

File details

Details for the file safe_agent_cli-0.4.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for safe_agent_cli-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f971430c549b14487b14717347260afc2ae960abac43833e8db534c6a3a2b0b4
MD5 cc23bab771ed26aa6b14d8717a192fa1
BLAKE2b-256 382e2a60c9426cbf400e275d9dc47d1748e8334ebd6b92c124e3d935e2dcc973

See more details on using hashes here.

Provenance

The following attestation bundles were made for safe_agent_cli-0.4.0-py3-none-any.whl:

Publisher: release.yml on agent-polis/safe-agent

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