kavach
Skill0 starsChanged 6 months agoApache-2.0View on GitHub
Add a default-deny execution gate around AI-agent actions in Python or Node / TypeScript using the kavach-sdk library. Use when the user is integrating Kavach, wants to add policy enforcement, drift detection, signed permit tokens, signed audit chains, secure channels, or default-deny request validation, mentions Gate, Guarded, PermitToken, ActionContext, EvaluateOptions, McpKavachMiddleware, guardTool, check_tool_call, evaluate_tool_call, or wants to wrap LangChain, LangGraph, MCP tool calls, Express, Fastify, or any agent tool-call code behind a deny-by-default check. Skip if Kavach is already wired up and the user is debugging unrelated code, or if the user is asking about a different policy engine (OPA, Cerbos, Casbin).
1 other project uses a version of this.
Adopted by
Most recently taken up by
- adhuniklabs/kavachtheir own version, first seen Aug 22, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- adhuniklabs/kavach★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 2 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Every call passes through three evaluators in order:
- Distinctive: line 37
Every error path fails closed.
- Very specific: line 109
Never fail open: Do not change Gate to skip evaluators, return Permit on errors, or downgrade Refuse to Permit.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Kavach: default-deny execution gates for AI agents
Next step, pick your language and load that doc immediately:
- Python: read python/README.md, then python/sdk.md.
- Node / TypeScript: read node/README.md, then node/sdk.md.
The rest of this file is the conceptual overview. Code, install commands, and full API surface live in the language folder you just picked.
Kavach is a Rust-core library, bound to both Python and Node / TypeScript, that puts a deny-by-default gate in front of every action an agent or service tries to execute. Both bindings ship the same surface: a policy gate, four built-in drift detectors, post-quantum signed permit tokens, a tamper-evident audit chain, and a secure channel primitive. The behaviour is identical across languages because every cryptographic primitive and every evaluator runs in the same compiled Rust core.
What it does
Every call passes through three evaluators in order:
- Policy decides whether the action matches a permit rule. Identity checks (
identity_kind,identity_role,identity_id) run inside this phase. No matching permit means Refuse. - Drift (optional, on by default) checks four signals about the principal's runtime context: device fingerprint, geo / IP, session age, and action-rate. Any violation can Refuse or Invalidate.
- Invariants (optional, present when configured) enforce hard numeric caps that beat any permissive policy. A policy permit that crosses an invariant becomes a Refuse.
Each call produces exactly one of three verdicts:
- Permit, with a signed
PermitTokenyou can hand to downstream services as proof the action passed the gate. - Refuse, with an evaluator name and a reason code so the calling code knows why it was blocked.
- Invalidate, which kills the entire session (used by drift detectors when something looks compromised).
Every error path fails closed. Missing parameters, unparseable durations, store outages, broadcaster failures, signer errors, and unverifiable tokens all collapse to Refuse rather than vacuously permit.
When this skill applies
Activate this skill when the user is doing any of the following in either Python or Node / TypeScript:
- Adding
kavach-sdkto a service. - Wrapping a LangChain tool, LangGraph node, MCP tool-call handler, Express / Fastify route, or any agent tool-call function behind a
Gate.evaluate(...)/Gate.check(...)call. - Authoring a Kavach policy (Python dict, TypeScript object, JSON, or TOML form).
- Wiring drift detectors (device fingerprint, geo location, session age, action count).
- Issuing or verifying signed
PermitTokens withPqTokenSigner. - Maintaining a tamper-evident
SignedAuditChainof agent actions. - Building a
SecureChannelbetween two services. - Asking how
Gate,ActionContext(Python) /EvaluateOptions(Node),Verdict,Guarded,guardTool, orcheck_tool_callwork.
Skip when the user is asking about a different policy engine, building a different library, or already has Kavach wired and is debugging an unrelated issue.
Capabilities at a glance
| Capability | Surface | Demonstrated in |
| Default-deny policy gate | Gate.evaluate / Gate.check | scenario 01 (quickstart), 02 (document access), 08 (loan approval) |
| Five policy loaders (TOML, TOML file, dict / object, JSON, JSON file) | Gate.from_dict, Gate.fromObject, etc. | scenario 23 (format equivalence in the older suite); every scenario uses one of the five |
| Four drift detectors (device, geo, session age, action count) | drift evaluator, EvaluateOptions fields | scenario 03 (geo drift), 04 (session hygiene), 11 (e-commerce fraud) |
| Tolerant-mode geo drift with distance threshold | geo_drift_max_km / geoDriftMaxKm | scenario 03 (password reset across geo) |
| Hard-cap invariants beating any permissive policy | invariants=[...] constructor arg | scenario 08 (loan approval regulator cap), 11 (e-commerce fraud cap) |
| Hot reload + empty-policy kill switch | gate.reload(toml) | scenario 19 (hot reload resilience in the older suite) |
| Observe-only rollout | observe_only=True / observeOnly: true | scenario 11 (e-commerce fraud rollout) |
| PQ-signed permit tokens (ML-DSA-65, hybrid Ed25519) | PqTokenSigner, verdict.permit_token | scenario 05 (signed permit), 06 (ephemeral permits), 09 (key rotation) |
| Hybrid-mode downgrade defence | is_hybrid / isHybrid enforcement | scenario 07 (PQ hybrid downgrade) |
| Tamper-evident signed audit chain with JSONL export | SignedAuditChain, AuditEntry | scenario 10 (break glass), 16 (healthcare PHI), 17 (PQ audit rotation), 20 (AI underwriter evidence) |
| Public-key directory + root-signed manifest | PublicKeyDirectory.from_signed_file / .fromSignedFile, DirectoryTokenVerifier | scenario 09 (key rotation), 15 (agent marketplace), 17 (audit rotation) |
| Cross-replica invalidation broadcast | InMemoryInvalidationBroadcaster, spawn_invalidation_listener | scenario 03 (geo drift broadcast), 14 (invalidation fanout) |
| Encrypted + signed + replay-protected byte channel | SecureChannel | scenario 13 (secure channel fleet), 15 (agent marketplace), 21 (customer deployed agent) |
| AI-agent attestation (prompt-injection defence) | signed intent + scope-hash binding | scenario 18 (AI agent attestation), 19 (cross-SaaS finance agent), 20 (AI underwriter), 21 (customer deployed) |
| MCP tool-call gating middleware | Python: McpKavachMiddleware.check_tool_call / evaluate_tool_call / invalidate_session. Node: McpKavachMiddleware.guardTool / checkToolCall / evaluateToolCall / invalidateSession | scenario 12 (HTTP + MCP middleware) |
Scenario numbers refer to the runnable suites at business-tests-python (Python, 21 scripts) and business-tests-node (Node, 21 scripts mirroring Python one-to-one).
Policy schema overview
One schema, five loaders, both languages:
[[policy]]
name = "agent_small_refunds"
effect = "permit"
priority = 10
conditions = [
{ identity_kind = "agent" },
{ action = "issue_refund" },
{ param_max = { field = "amount", max = 5000.0 } },
]Same vocabulary in a Python dict or a TypeScript object. The condition variants (identity_kind, identity_role, identity_id, action, resource, param_max, param_min, param_in, rate_limit, session_age_max, time_window) are identical across all formats. Misspelled condition names are rejected at load time in every loader, in every language.
For the full grammar (conditions, durations, time-window syntax, priority order, default-deny semantics, hot-reload behaviour), read references/policy-language.md.
Pick your language
| Language | Entry point | When |
| Python 3.10+ | python/README.md | Backend service in Python, FastAPI / Django / Flask, LangChain / LangGraph orchestration, Jupyter / data pipelines. |
| Node / TypeScript | node/README.md | Backend service in Node, Express / Fastify, MCP server, agent runtime, Edge functions, anything in the npm ecosystem. |
Each language folder ships the same five deep-reference docs: README.md (install + quickstart), sdk.md (full surface), drift-detectors.md, audit-and-pq.md, secure-channel.md, plus a runnable scaffold (scaffold.py / scaffold.ts).
Shared across both languages: references/policy-language.md (policy grammar) and assets/policies.example.toml (kitchen-sink TOML example).
Hard rules (apply to every language)
- Never fail open. Do not change
Gateto skip evaluators, return Permit on errors, or downgrade Refuse to Permit. The library's contract is fail-closed; integrators rely on it for compliance and incident response. - Never skip invariants when refactoring policies. Invariants are the regulator-grade hard floor that beats any permissive policy. Removing them in favour of a
param_maxpolicy condition silently weakens the system. - No implicit allow. An empty policy set is valid and means deny-everything (useful as a kill switch). To permit anything, write a policy with
effect: "permit"and the conditions that match. - Do not install third-party crypto libraries to handle Kavach signatures. The SDK ships every algorithm Kavach uses (ML-DSA-65, ML-KEM-768, Ed25519, X25519, ChaCha20-Poly1305) compiled in via PyO3 (Python) and napi-rs (Node). External PQ libraries are not guaranteed interoperable.
- Sign-failure is fail-closed. A
PqTokenSignerthat errors during evaluation turns the verdict into Refuse, never a permit-without-signature. - Always pass UUIDs for
session_id/sessionId. A non-UUID value is silently replaced with a fresh random UUID, which means rate-limit and drift state will not match between calls that share a non-UUID string.
Verifying a working integration
A successful integration produces a Permit verdict carrying a fresh tokenId for in-policy actions, and a Refuse / Invalidate verdict (with the right evaluator and code) for out-of-policy actions. Both languages ship 21 runnable scenarios that pin the full contract end-to-end:
- Python: github.com/SarthiAI/Kavach/tree/main/business-tests-python
- Node: github.com/SarthiAI/Kavach/tree/main/business-tests-node
Each suite runs in roughly twelve to thirteen seconds and exits 0 on full pass.
Next step (again, do not skip)
Load the language doc for the user's stack now. This SKILL.md is overview only; it does not contain install commands, working code, or the full API surface.
- Python: python/README.md and python/sdk.md.
- Node / TypeScript: node/README.md and node/sdk.md.
- Shared by both: references/policy-language.md, assets/policies.example.toml.
License + repo
Kavach the library is released under the Elastic License 2.0 (source-available; embed and modify, but do not repackage as a competing hosted service). This skill content (Markdown, example policies, scaffold scripts) is Apache-2.0 and freely embeddable in any agent runtime.
For surfaces not yet covered in this skill (HTTP middleware deep dive, multi-replica Redis deployments, additional language bindings), see the Kavach roadmap.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

