The Security and Command Approval system is a safeguard layer in Hermes Agent designed to intercept and manage the execution of potentially dangerous commands issued by the AI or users. It balances flexibility and security by detecting destructive or risky operations and requiring explicit user approval before execution, thus preventing accidental system damage, unauthorized actions, or malicious code execution.
This system employs multiple overlapping mechanisms to provide a comprehensive approval workflow:
tools.approval tools/approval.py1-9contextvars, supporting one-time, per-session, and permanent approvals tools/approval.py35-50config.yaml and a YOLO shortcut mode to bypass approvals within a session tools/approval.py30-35execute_code, a strict environment variable blocklist prevents the leakage of Hermes' own provider secrets into the child process tools/code_execution_tool.py135-161Sources: tools/approval.py1-77 agent/redact.py1-8 tools/code_execution_tool.py135-161
The security and approval subsystem fits into the Hermes tool execution pathway as a gatekeeper between the agent issuing commands and their actual execution on the host system.
Sources: tools/approval.py35-77 agent/redact.py1-15 tools/environments/local.py17-21 tools/process_registry.py17-30
Hermes uses regex patterns to scan commands for destructive operations. The detection logic performs command normalization to prevent homograph-based bypasses where lookalike characters are used to hide malicious commands tools/approval.py20-23
| Pattern Category | Description |
|---|---|
| Recursive Delete | Matches rm -rf, rm -r, or rm --recursive to prevent mass deletion tests/tools/test_approval.py110-120 |
| Windows Delete | Flags cmd /c del /f /q, rmdir /s, and PowerShell destructive commands tests/tools/test_approval.py171-180 |
| Shell Injections | Detects bash -c, `curl |
| Verification Exemption | Specifically allows non-recursive cleanup of Hermes verification artifacts in temp directories tests/tools/test_approval.py122-129 |
Sources: tools/approval.py1-23 tests/tools/test_approval.py110-183
To prevent credential leakage, Hermes implements a regex-based redaction system that masks sensitive data before it reaches logs or tool outputs agent/redact.py1-8
sk-), GitHub tokens (ghp_), AWS keys (AKIA), Slack tokens, and generic KEY=value assignments agent/redact.py71-119access_token, api_key) and JSON body keys while leaving benign code (e.g., os.getenv, process.env) untouched agent/redact.py17-149_REDACT_ENABLED to prevent LLM-generated commands from disabling security mid-session agent/redact.py59-69Sources: agent/redact.py1-154 tests/agent/test_redact.py18-170
When spawning local subprocesses (via terminal or execute_code), Hermes strictly sanitizes the environment to prevent credential leakage and misrouting tests/tools/test_local_env_blocklist.py1-9
OPENAI_API_KEY, ANTHROPIC_API_KEY, AWS_BEARER_TOKEN_BEDROCK) is stripped from child processes tests/tools/test_local_env_blocklist.py64-115HERMES_HOME, HERMES_PROFILE) is permitted to reach the child context tools/code_execution_tool.py167-173KEY, TOKEN, SECRET, or PASSWORD is automatically scrubbed unless it is an OS-essential variable tools/code_execution_tool.py151-161Sources: tools/code_execution_tool.py135-173 tests/tools/test_local_env_blocklist.py64-115
The system manages approval state using thread-safe structures to support concurrent sessions in the Gateway and ACP server.
Hermes uses contextvars to isolate session identities and interactive flags. This prevents race conditions where one session's approval state could clobber another's tools/approval.py35-64
set_hermes_interactive_context(bool): Binds interactive mode for the current thread or asyncio task tools/approval.py69-76set_current_session_key(session_key): Binds the active approval session key to the current context tools/approval.py171-173_fire_approval_hook(hook_name): Invokes plugin lifecycle hooks (pre_approval_request, post_approval_response) for observability tools/approval.py96-115Sources: tools/approval.py35-173 agent/redact.py1-15 tools/code_execution_tool.py135-173 tools/process_registry.py142-160
YOLO mode bypasses dangerous command prompts. To prevent privilege escalation via prompt injection, this mode is frozen at module import time tools/approval.py32-35
_YOLO_MODE_FROZEN reads HERMES_YOLO_MODE once. Any subsequent environment changes by the agent or skills inside the process are ignored tools/approval.py33-35When enabled, the system uses an auxiliary LLM via _smart_approve to analyze command risk tests/tools/test_approval.py66-70
APPROVE, the command proceeds without a user prompt._prepare_smart_approval_observer which redacts the command before emitting the hook tools/approval.py123-155Sources: tools/approval.py30-168 tests/tools/test_approval.py60-106
Refresh this wiki
This wiki was recently refreshed. Please wait 4 days to refresh again.