sec0-sdk/guard is the smallest Sec0 integration surface. Use it when you want policy decisions in application code without wrapping a tool server.
Typical uses:
- outbound message checks before sending to Slack, Discord, email, or SMS
- preflight checks around external API calls
- tool or MCP decisions in apps that do not use
sec0-sdk/middleware - approval workflows that need a simple create, wait, and resolve loop
Core API
createSec0Guard(...) returns three methods:
| Method | Use it for |
|---|---|
guard.check(input) | get a decision without executing anything |
guard.execute(input, actionFn, handlers?) | run the action only when the decision allows it, redacts it, or resolves escalation |
guard.waitForResolution(escalationId, opts?) | wait on an existing escalation |
| Outcome | Meaning |
|---|---|
allow | proceed as-is |
redact | execute with redacted content |
block | stop immediately |
escalate | create an escalation and either wait or return pending |
Choose a Mode
| Mode | Policy source |
|---|---|
standalone | local GuardPolicy, local policy.yaml, or local PolicyObject |
dashboard | remote control-plane policy only |
hybrid | local plus remote, with remote-first or local-first precedence |
Standalone Example
Use standalone mode when the application must work without network access:Dashboard Example
Use dashboard mode when policy should come from the control plane:Hybrid Example
Use hybrid mode when the remote policy should be primary but local fallback must still work:Execute with Redaction or Block Handlers
guard.execute(...) lets you customize what happens on redact and block outcomes:
Escalations and Approvals Transport
The guard can create and wait on escalations, and it can forward those escalation events to the open-source approvals bridge.escalation.created and escalation.finalized events to the bridge. Deploy the reference worker in apps/sec0-approvals-bridge when you want Discord or Telegram approval flows.
If your application already knows when to escalate and does not need policy evaluation, use createEscalationManager(...) from sec0-sdk/escalation instead of sec0-sdk/guard. Guard now builds on that same shared escalation lifecycle.
Waiting on an Existing Escalation
If your application stores the escalation id and resolves it later:approved, rejected, expired, or timeout.
The equivalent standalone API is:
When to Use Guard vs Middleware
Usesec0-sdk/guard when the action lives in application code. Use sec0-sdk/middleware when the action is a tool-server invocation and you want registry freeze, source hashing, signed envelopes, and server-side policy enforcement on every call.