Skip to main content

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

Metadata

Release files for vaspera-guard 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vaspera-guard 0.2.3
File Size Uploaded Provenance
vaspera_guard-0.2.3.tar.gz 9.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for vaspera-guard 0.2.3
File Interpreter ABI Platform
vaspera_guard-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 18.8 kB

Release files / vaspera_guard-0.2.3.tar.gz

Download URL vaspera_guard-0.2.3.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7b46a7e42e2e650bf4720c69dfcbd4020d04443dac15c26ef3adb4b84e86a7f9
BLAKE2b-256 checksum
How to use checksums
f50d1b995493241f5aad718939206d8fa4b0980a680ad68c02bf0f93dd9930d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / vaspera_guard-0.2.3-py3-none-any.whl

Download URL vaspera_guard-0.2.3-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a3eb646eac2f78045ffec12bf1c2de41d556f51459de9773c49c951d41493c1
BLAKE2b-256 checksum
How to use checksums
877be622bb57477f4bf8ca93dbc7ef00acbcb9cae43a9321688e33ff6876d2b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for vaspera-guard 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page