Sovereign Interceptor Patterns
Two-stage security gate that sits above anti-injection guards: AST scan of generated code + honey-vault canary detection.
When to Use
- Building an agent system that self-generates and executes code at runtime
- Hardening an existing agent pipeline against supply-chain or code-injection attacks
- Adding canary token infrastructure to detect compromised agents early
- Auditing tool-call payloads before execution in a multi-agent swarm
Do NOT use for
- Static linting of developer-written code (use ESLint/SonarQube instead)
- Runtime performance profiling (use chrome-devtools-performance-trace)
- Replacing sandboxing — interceptor is a gate, not a jail
Stage 1: AST Scan
import { SovereignSecurityInterceptor } from 'core/gates/sovereign-interceptor.js';
const interceptor = new SovereignSecurityInterceptor({
allowedCommands: ['git', 'node', 'python3'],
});
// Scan agent-generated code before hot-loading
const result = interceptor.scanCode(agentGeneratedSource, 'agent-42:task-7');
if (!result.safe) {
// violations: [{ type: 'PROCESS_ENV_ACCESS', loc: {...} }]
throw new Error(`AST violation: ${result.violations[0].type}`);
}
Stage 2: Honey-Vault Detection
// Any payload touching STRIPE_SECRET_KEY, OPENAI_API_KEY, HONEY_* → quarantine
try {
interceptor.checkHoneyVault({ command: 'send', agentId: 'a-42', args: [somePayload] });
} catch (e) {
if (e instanceof HoneyVaultTripError) {
swarmRouter.quarantine(e.agentId, 'HONEY_VAULT_TRIP');
}
}
Command Allow-List
// Block any command not in the approved set
interceptor.verifyCommand('curl', ['https://api.example.com']); // PASS if curl in list
interceptor.verifyCommand('eval', []); // THROW SovereignBlockError
Fingerprinting for Audit Chain
const fp = interceptor.fingerprint({ command, args, agentId, ts: Date.now() });
secureLogger.logAction(agentId, command, 'PASS', { fingerprint: fp });
AST Violations Detected
| Violation | Pattern |
|---|---|
DANGEROUS_CALL |
eval(), exec(), execSync(), spawnSync() |
PROCESS_ENV_ACCESS |
process.env.* |
CHILD_PROCESS_ACCESS |
child_process.* |
PATH_TRAVERSAL_STRING |
String literals containing ../ |
HONEY_STRING_LITERAL |
Known honey-vault key names in literals |
Anti-Fake-Pass Checklist
- AST scan result
safe: truebefore executing generated code -
checkHoneyVault()called on ALL payloads, not just suspicious ones -
scanCode()called with source string, not file path (avoid TOCTOU) - Violations array inspected — not just
safeboolean -
SovereignBlockError.exitCodepropagated up to kill the pipeline