Python SDK
v0.1.0Scan AI agent memory for prompt injection and credential leaks in 3 lines of code.
Installation
Requires Python 3.9+. Zero required dependencies beyond httpx.
Quick Start
Get an API key from the Cloud Dashboard, then scan content before it reaches your agent's memory.
from shieldcortex import ShieldCortex
client = ShieldCortex(api_key="sc_live_...")
result = client.scan("user input to remember")
if result.allowed:
save_to_memory(result)
else:
print(f"Blocked: {result.firewall.reason}")
print(f"Threats: {result.firewall.threat_indicators}") Async Support
Full async/await support with AsyncShieldCortex.
from shieldcortex import AsyncShieldCortex
async with AsyncShieldCortex(api_key="sc_live_...") as client:
result = await client.scan("user input")
# Batch scan up to 100 items
batch = await client.scan_batch([
BatchItem(content="item 1"),
BatchItem(content="item 2"),
]) API Reference
| Category | Methods |
|---|---|
| Scanning | scan(), scan_batch(), scan_skill() |
| Audit | get_audit_logs(), get_audit_entry(), get_audit_stats(), get_audit_trends(), export_audit_logs(), iter_audit_logs() |
| Quarantine | get_quarantine(), get_quarantine_item(), review_quarantine_item() |
| API Keys | create_api_key(), list_api_keys(), revoke_api_key() |
| Teams | get_team(), update_team(), get_team_members(), get_usage() |
| Invites | create_invite(), list_invites(), delete_invite(), resend_invite() |
| Devices | get_devices(), register_device(), update_device(), device_heartbeat() |
| Alerts | get_alerts(), create_alert(), update_alert(), delete_alert() |
| Webhooks | get_webhooks(), create_webhook(), update_webhook(), delete_webhook(), test_webhook() |
| Firewall Rules | get_firewall_rules(), get_active_firewall_rules(), create_firewall_rule(), update_firewall_rule(), delete_firewall_rule() |
| Iron Dome Patterns | get_injection_patterns(), create_injection_pattern(), update_injection_pattern(), test_injection_pattern(), delete_injection_pattern() |
| Iron Dome Policies | get_iron_dome_policies(), create_iron_dome_policy(), update_iron_dome_policy(), set_default_iron_dome_policy(), delete_iron_dome_policy() |
| Billing | create_checkout_session(), create_portal_session() |
CrewAI Integration
Wrap your CrewAI agent's memory with ShieldCortex. The ShieldCortexMemoryGuard scans every memory write and raises MemoryBlockedError for threats.
from shieldcortex import ShieldCortex
from shieldcortex.integrations.crewai import ShieldCortexMemoryGuard, MemoryBlockedError
client = ShieldCortex(api_key="sc_live_...")
guard = ShieldCortexMemoryGuard(client, mode="strict")
try:
guard.check("content to remember")
except MemoryBlockedError as e:
print(f"Blocked: {e.result.firewall.reason}") Modes: strict (blocks + quarantines), balanced (blocks only), permissive (log only).
LangChain Integration
Add ShieldCortex as a LangChain callback handler. Scans every LLM input and output automatically.
from shieldcortex import AsyncShieldCortex from shieldcortex.integrations.langchain import ShieldCortexCallbackHandler client = AsyncShieldCortex(api_key="sc_live_...") handler = ShieldCortexCallbackHandler(client, raise_on_block=True) llm = ChatOpenAI(callbacks=[handler])
Error Handling
from shieldcortex import ShieldCortex, AuthError, RateLimitError, ValidationError
client = ShieldCortex(api_key="sc_live_...")
try:
result = client.scan("content")
except AuthError:
print("Invalid API key")
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except ValidationError as e:
print(f"Invalid input: {e}") Resources
- PyPI Package
- GitHub Repository
- Get an API Key — free tier includes 500 scans/month
- Full Documentation