Python SDK for clawdstrike security verification
Project description
clawdstrike
Python SDK for Clawdstrike security verification.
Installation
pip install clawdstrike
Quick Start
from clawdstrike import Clawdstrike
cs = Clawdstrike.with_defaults("strict")
# Check file access
decision = cs.check_file("/etc/shadow")
if decision.denied:
print(f"Blocked: {decision.message}")
# Check network egress
decision = cs.check_network("api.openai.com")
print(f"Allowed: {decision.allowed}")
Usage
Facade API (recommended)
from clawdstrike import Clawdstrike, Decision, DecisionStatus
# Built-in rulesets: "permissive", "default", "strict", "ai-agent", "cicd"
cs = Clawdstrike.with_defaults("strict")
# All check methods return a Decision
decision = cs.check_file("/etc/passwd")
decision = cs.check_command("rm -rf /")
decision = cs.check_network("evil.com", 443)
decision = cs.check_patch("/app/main.py", diff_str)
decision = cs.check_mcp_tool("shell_exec", {"cmd": "ls"})
# Decision properties
print(decision.status) # DecisionStatus.DENY
print(decision.denied) # True
print(decision.allowed) # False
print(decision.message) # "Access to forbidden path: ..."
print(decision.guard) # "forbidden_path"
print(decision.per_guard) # List of individual GuardResult objects
Sessions
cs = Clawdstrike.with_defaults("default")
session = cs.session(agent_id="my-agent")
session.check_file("/app/src/main.py")
session.check_network("api.openai.com")
session.check_file("/home/user/.ssh/id_rsa")
summary = session.get_summary()
print(f"Checks: {summary.check_count}")
print(f"Allowed: {summary.allow_count}")
print(f"Denied: {summary.deny_count}")
print(f"Blocked: {summary.blocked_actions}")
Loading from YAML
from clawdstrike import Clawdstrike
# From file
cs = Clawdstrike.from_policy("policy.yaml")
# From YAML string
cs = Clawdstrike.from_policy('''
version: "1.1.0"
name: my-policy
extends: strict
guards:
egress_allowlist:
allow:
- "api.myservice.com"
''')
Low-level API
from clawdstrike import Policy, PolicyEngine, FileAccessAction, GuardContext
policy = Policy.from_yaml_file("policy.yaml")
engine = PolicyEngine(policy)
context = GuardContext(cwd="/app")
results = engine.check(FileAccessAction(path="/app/src/main.py"), context)
print(all(r.allowed for r in results))
Native Engine (Recommended)
Install the native extension for full Rust-powered evaluation:
pip install hush-native
The SDK automatically uses the native engine when available. All 12 guards run in Rust with full detection capabilities.
Without the native extension, the SDK falls back to pure Python with 9 guards and heuristic-only detection.
from clawdstrike import Clawdstrike, NATIVE_AVAILABLE, init_native
# Check if native engine is available
print(f"Native available: {NATIVE_AVAILABLE}")
print(f"Native engine: {init_native()}")
# The facade auto-selects the best backend
cs = Clawdstrike.with_defaults("strict")
print(f"Backend: {cs._backend.name}") # "native" or "pure_python"
Explicit Backend Selection
from clawdstrike import Clawdstrike
from clawdstrike.backend import NativeEngineBackend, PurePythonBackend
from clawdstrike.policy import Policy, PolicyEngine
# Force pure Python backend
yaml = 'version: "1.1.0"\nname: test\nextends: strict\n'
policy = Policy.from_yaml_with_extends(yaml)
cs = Clawdstrike(PurePythonBackend(PolicyEngine(policy)))
# Force native backend (raises if unavailable)
backend = NativeEngineBackend.from_ruleset("strict")
cs = Clawdstrike(backend)
Features
- Native Rust engine (via hush-native) with all 12 guards
- Pure Python fallback with 9 guards:
- ForbiddenPathGuard - Blocks sensitive filesystem paths
- PathAllowlistGuard - Allowlist-based path access control
- EgressAllowlistGuard - Controls network egress by domain
- SecretLeakGuard - Detects secrets in file writes
- PatchIntegrityGuard - Validates patch safety
- ShellCommandGuard - Blocks dangerous shell commands
- McpToolGuard - Restricts MCP tool invocations
- PromptInjectionGuard - Detects prompt injection
- JailbreakGuard - Detects jailbreak attempts
- Facade API with
Clawdstrikeclass andDecisionreturn type - Stateful sessions with
ClawdstrikeSession - Custom exception hierarchy (
ClawdstrikeErrorbase) - Policy engine with YAML configuration and inheritance
- Receipt signing and verification with Ed25519
- Typed action variants (frozen dataclasses)
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clawdstrike-0.2.0.tar.gz.
File metadata
- Download URL: clawdstrike-0.2.0.tar.gz
- Upload date:
- Size: 161.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c461e8b5889f3f33f0b86461d2f5e0710205acb5790afe42477322c283bd288
|
|
| MD5 |
13ca3ae2e3580e34323b3f82cbd21edb
|
|
| BLAKE2b-256 |
de9a03a1424203ca612045904ebc0481d7bdc9a96e203cf37c5807b2aabd6945
|
File details
Details for the file clawdstrike-0.2.0-py3-none-any.whl.
File metadata
- Download URL: clawdstrike-0.2.0-py3-none-any.whl
- Upload date:
- Size: 108.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bbfd9bd83e85bfc1eb8f3d7b119873474126622c1f1c72ed49e6ef2ac357a1b
|
|
| MD5 |
aa75df8dc2ccd7ff5f7d7b95848c8176
|
|
| BLAKE2b-256 |
73e02a4eb203256ad47ed612b23942964094ee4c9fa48c705d4e1958720583c1
|