Skip to main content

Safety & governance layer for AI agents

Project description

VasperaGuard Python SDK

The safety & governance layer for AI agents.

Installation

pip install vaspera-guard

Quick Start

from vaspera_guard import Guard

# Initialize with API key
guard = Guard(api_key="vg_...")
# Or set VASPERA_GUARD_API_KEY environment variable

# Check if a command is safe
result = guard.check("rm -rf /tmp/cache")

if result.allowed:
    # Safe to execute
    subprocess.run(command, shell=True)
elif result.requires_approval:
    # Request human approval
    approval = guard.request_approval(
        result.check_id,
        command,
        channel="slack",
        slack_channel="#devops"
    )
    print(f"Approval requested: {approval.approve_url}")
else:
    # Command blocked
    print(f"Blocked: {result.reason}")
    print(f"Suggestions: {result.suggestions}")

Usage with AI Agents

from vaspera_guard import Guard, AgentContext

guard = Guard(
    api_key="vg_...",
    agent_id="my-coding-agent",
    environment="production"
)

async def agent_execute(command: str):
    """Execute a command with VasperaGuard protection."""

    # Check safety before execution
    result = guard.check(
        command,
        context=AgentContext(
            environment="production",
            project="backend-api",
            working_directory="/app"
        )
    )

    if result.blocked:
        return f"Command blocked: {result.reason}"

    if result.requires_approval:
        approval = guard.request_approval(
            result.check_id,
            command,
            channel="slack",
            slack_channel="#agent-approvals",
            reason="Agent needs to run this for deployment"
        )
        # Wait for approval (max 5 minutes)
        final = guard.wait_for_approval(approval.approval_id, timeout=300)
        if not final.is_approved:
            return "Approval denied"

    # Execute the command
    return subprocess.run(command, shell=True, capture_output=True)

Check and Execute Pattern

from vaspera_guard import Guard

guard = Guard()

def run_cmd(cmd):
    return subprocess.run(cmd, shell=True, capture_output=True)

# Automatically check and execute
result = guard.check_and_execute(
    "ls -la",
    executor=run_cmd,
    on_blocked=lambda r: print(f"Blocked: {r.reason}"),
    on_approval_required=lambda r: print(f"Needs approval: {r.approval_url}")
)

Custom Policies

from vaspera_guard import Guard, PolicyRule

guard = Guard()

# Create a policy for production
policy = guard.create_policy(
    name="production-safety",
    description="Strict safety rules for production",
    rules=[
        PolicyRule(pattern="DROP TABLE", action="block"),
        PolicyRule(pattern="rm -rf", action="require_approval"),
        PolicyRule(pattern="chmod 777", action="warn"),
    ],
    environments=["production"]
)

# Use the policy
result = guard.check("DROP TABLE users", policy_id=policy.policy_id)
# result.blocked == True

Audit Trail

# Get audit log
entries = guard.get_audit_log(
    agent_id="my-agent",
    risk_level="high",
    limit=50
)

for entry in entries:
    print(f"{entry.timestamp}: {entry.command} -> {entry.check_result}")

Part of the Vaspera Platform

VasperaGuard works best with the full Vaspera ecosystem:

API Reference

Guard

  • check(command, agent_id, context, policy_id) - Check command safety
  • check_and_execute(command, executor, ...) - Check and execute if safe
  • request_approval(check_id, command, ...) - Request human approval
  • get_approval_status(approval_id) - Check approval status
  • wait_for_approval(approval_id, timeout) - Wait for approval decision
  • create_policy(name, rules, ...) - Create custom policy
  • list_policies() - List all policies
  • get_audit_log(...) - Get audit trail
  • get_stats() - Get usage statistics

Models

  • CheckResult - Result from safety check
  • ApprovalResult - Result from approval request
  • AgentContext - Context about the agent
  • Policy - Safety policy
  • PolicyRule - Rule in a policy
  • AuditEntry - Audit log entry

License

MIT

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

vaspera_guard-0.1.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

vaspera_guard-0.1.1-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file vaspera_guard-0.1.1.tar.gz.

File metadata

  • Download URL: vaspera_guard-0.1.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for vaspera_guard-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cae9d57bbc61642e0b9931e04e255869b4246c8a629d19489aedc46efd962116
MD5 76da72c3287037c06199a9affff71466
BLAKE2b-256 b05969b1291f36cb155b653b5f5e57c3839b396677e60ac0545a7c65c796793a

See more details on using hashes here.

File details

Details for the file vaspera_guard-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: vaspera_guard-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for vaspera_guard-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f092f44642ee0860ce815cc41689bc0e81cd17767ba9e13f99b7d1d6c900b7cc
MD5 9b9eb16728cc3b857e141d57582109b2
BLAKE2b-256 590ec4287e3db69dd59c7f3065af8a11f34fca56c74d2812fa6a4e268763c45a

See more details on using hashes here.

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