Skip to main content

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)

The SDK automatically uses the bundled native engine when available. All 12 guards run in Rust with full detection capabilities.

On unsupported platforms, the SDK falls back to pure Python with 9 guards and heuristic-only detection.

Native wheels are published for:

  • Linux: manylinux (x86_64, aarch64)
  • macOS: x86_64, arm64
  • Windows: x86_64
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 DaemonEngineBackend, 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)

# Force daemon-backed evaluation through hushd
daemon = DaemonEngineBackend("https://hushd.example.com", api_key="dev-token")
cs = Clawdstrike(daemon)

Origin-Aware Checks

Origin-aware enforcement is available on:

  • the bundled native Rust backend
  • hushd via Clawdstrike.from_daemon(...) or DaemonEngineBackend

The pure-Python backend does not enforce policy.origins. It fails closed with UnsupportedOriginFeatureError if you pass origin or use origin.output_send.

from clawdstrike import Clawdstrike

origin = {
    "provider": "slack",
    "tenant_id": "T123",
    "space_id": "C456",
    "actor_role": "incident_commander",
}

cs = Clawdstrike.from_daemon("https://hushd.example.com", api_key="dev-token")

decision = cs.check_mcp_tool(
    "read_file",
    {"path": "/srv/runbook.md"},
    origin=origin,
)

send_decision = cs.check_output_send(
    "Posting sanitized status update",
    target="slack://incident-room",
    mime_type="text/plain",
    metadata={"thread_id": "1712502451.000100"},
    origin=origin,
)

Per-check origin changes also work through sessions:

session = cs.session(session_id="sess-123", agent_id="triage-bot")

session.check_file(
    "/srv/runbook.md",
    origin={"provider": "github", "space_id": "repo-1"},
)

session.check_output_send(
    "Ready for review",
    target="slack://incident-room",
    origin={"provider": "slack", "space_id": "C456"},
)

Features

  • Native Rust engine (bundled in clawdstrike wheels on supported platforms) 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 Clawdstrike class and Decision return type
  • Stateful sessions with ClawdstrikeSession
  • Custom exception hierarchy (ClawdstrikeError base)
  • Policy engine with YAML configuration and inheritance
  • Receipt signing and verification with Ed25519
  • Typed action variants (frozen dataclasses)

License

Apache-2.0

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

clawdstrike-0.2.6.tar.gz (234.8 kB view details)

Uploaded Source

Built Distributions

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

clawdstrike-0.2.6-py3-none-any.whl (143.9 kB view details)

Uploaded Python 3

clawdstrike-0.2.6-cp310-abi3-win_amd64.whl (4.4 MB view details)

Uploaded CPython 3.10+Windows x86-64

clawdstrike-0.2.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.7 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

clawdstrike-0.2.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.4 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

clawdstrike-0.2.6-cp310-abi3-macosx_11_0_arm64.whl (4.3 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

clawdstrike-0.2.6-cp310-abi3-macosx_10_12_x86_64.whl (4.6 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file clawdstrike-0.2.6.tar.gz.

File metadata

  • Download URL: clawdstrike-0.2.6.tar.gz
  • Upload date:
  • Size: 234.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for clawdstrike-0.2.6.tar.gz
Algorithm Hash digest
SHA256 cf367380309a929f913b04980b6f650e1b11e96e4584cbf0fa31232e0d173de4
MD5 8241901578f0de5510c1e04b905255d7
BLAKE2b-256 70f94e59a1a641c3bb7a94ce1831cf40bcb3d1e54f2bcac6491109f4f33bd0b4

See more details on using hashes here.

File details

Details for the file clawdstrike-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: clawdstrike-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 143.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for clawdstrike-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 fda4be23266c67bcc68709bd4c607b8862eee95e2ff6a0da56616ec20e5f0a55
MD5 797dfe565b26dfe1a768fd63aab1547a
BLAKE2b-256 937005c1dcd6dee4d9e1e2d178b94fb7c1ec99b2715d92e15b3fd50dd2912593

See more details on using hashes here.

File details

Details for the file clawdstrike-0.2.6-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: clawdstrike-0.2.6-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for clawdstrike-0.2.6-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 9c7d1ec9fd3aa26749a8ab31ec22343caaf330097afc0f7ba49b5b7aed2d11e1
MD5 1ad11a597ac844d7b17d277b97d339b0
BLAKE2b-256 1bddb851bd65bd31a46f6a445c31c59b0360ac090295fee920ec6709057eb5f8

See more details on using hashes here.

File details

Details for the file clawdstrike-0.2.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for clawdstrike-0.2.6-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03b0a7b5fa62901911103c8a22b93553c22cb4cfad2e6691f074c6595138a968
MD5 622f3221cf3578a2513551c646f4c0ae
BLAKE2b-256 414c57abecb51651ad02cf1f81b7d418ac826544cae88c24e8b7430488a8e4c8

See more details on using hashes here.

File details

Details for the file clawdstrike-0.2.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for clawdstrike-0.2.6-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a0aee095c62c4d39a920fd0b62809bc114deba96653c3d853d9c72dcd10ddef1
MD5 182f730bacc7b608bc615f122a0bff03
BLAKE2b-256 126f1ff1b2ee1d1feac3333fea5cea76565d4b65b4dbc8a77c4a474a8c2be455

See more details on using hashes here.

File details

Details for the file clawdstrike-0.2.6-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for clawdstrike-0.2.6-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f938a495aa30c72d801625b481828811bc1638d7a9c230322a1420bdfc3fea4f
MD5 2c37b83be77f0a6274df1152c9c82e20
BLAKE2b-256 2ea65dbc2a53ab490db4ad4520f0ba91b182838d60e74b3625244003e5888ce8

See more details on using hashes here.

File details

Details for the file clawdstrike-0.2.6-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for clawdstrike-0.2.6-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a60fafcf5061da81b682a08025d79c6fe82424f31338817a01fac6f565e4d0e8
MD5 ac3d594fcc38d8352dde2619352a41ae
BLAKE2b-256 7cf2b231c0a6f45d898270dc2b551f0aa7b5b1bfa63e32aa0c4b8a4db4bda58f

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