Source-linked AI summary
Don't Let the Claw Grip Your Hand: A Security Analysis and Defense Framework for OpenClaw
Zhengyang Shan, Jiayun Xin, Yue Zhang, Minghui Xu
TL;DR
Code agents’ shell and file capabilities create serious execution risks, including indirect prompt injection and sandbox escape. This paper evaluates OpenClaw across 47 adversarial scenarios and introduces a dual-mode HITL defense layer. Baseline security varies substantially by backend, while HITL raises defense rates substantially but leaves pattern-coverage and sandbox-escape weaknesses.
Problem
OpenClaw’s shell and file-operation capabilities create attack opportunities, while its native security depends substantially on backend LLM behavior.
Method
The paper evaluates six LLM backends across 47 adversarial scenarios in six attack categories, comparing baseline execution with a layered HITL defense.
Results
Baseline defense rates range from 17% to 83%, while the HITL defense layer achieves effective defense rates up to 91.5%.
Takeaways & Limitations
Human-agent collaborative defense substantially hardens OpenClaw, but sandbox escape remains a persistent weakness requiring architectural solutions beyond pattern-based detection.
Takeaways & Limitations
Pattern-based detection can miss novel or fragmented attacks that do not match predefined rules, and DeepSeek executed all three tested encoding scenarios in both modes.
Abstract
from arXiv · showhide
Code agents powered by large language models can execute shell commands on behalf of users, introducing severe security vulnerabilities. This paper presents a two-phase security analysis of the OpenClaw platform. As an open-source AI agent framework that operates locally, OpenClaw can be integrated with various commercial large language models. Because its native architecture lacks built-in security constraints, it serves as an ideal subject for evaluating baseline agent vulnerabilities. First, we systematically evaluate OpenClaw's native resilience against malicious instructions. By testing 47 adversarial scenarios across six major attack categories derived from the MITRE ATLAS and ATT\&CK frameworks, we have demonstrated that OpenClaw exhibits significant inherent security issues. It primarily relies on the security capabilities of the backend LLM and is highly susceptible to sandbox escape attacks, with an average defense rate of only 17\%. To mitigate these critical security gaps, we propose and implement a novel Human-in-the-Loop (HITL) defense layer. We utilize a dual-mode testing framework to evaluate the system with and without our proposed intervention. Our findings show that the introduced HITL layer significantly hardens the system, successfully intercepting up to 8 severe attacks that completely bypassed OpenClaw's native defenses. By combining native capabilities with our HITL approach, the overall defense rate improves to a range of 19\% to 92\%. Our study not only exposes the intrinsic limitations of current code agents but also demonstrates the effectiveness of human-agent collaborative defense strategies.
I. INTRODUCTION
OpenClaw’s broad system access enables useful code-agent operations but also creates attack opportunities, especially when external content contains malicious instructions. The paper evaluates these risks and introduces a layered HITL defense with dual-mode testing.
- Motivation: OpenClaw agents can execute shell commands and manipulate project files, making the capabilities that provide utility potential attack vectors.The framework accepts natural-language requests and converts them into executable tool calls.
- Motivation: Indirect prompt injection can hide malicious commands in project documentation, causing agents to exfiltrate credentials, establish reverse shells, or modify system configurations.The attack succeeds when the agent cannot distinguish legitimate user requests from injected content.
- Research Focus: The paper examines OpenClaw’s adversarial-prompt vulnerabilities, layered mitigation strategies, difficult attack categories, and practical defense limits.The evaluation focuses on OpenClaw’s tool-execution security rather than general conversational safety.
- Threat Categories: Six primary threat categories include encoding evasion, sandbox boundary violations, indirect prompt injection, supply-chain compromise, resource exhaustion, and privilege escalation.The paper documents attack techniques and potential impacts for each category.
- Defense Framework: The proposed HITL layer intercepts tool calls using allowlisting, pattern-based risk classification, semantic intent judging, and mandatory approval for high-risk operations.The framework uses 35 detection rules and does not require modifying the underlying LLM.
- Evaluation: The dual-mode framework tests 47 adversarial scenarios across six categories under baseline and defended conditions to compare defense effectiveness.The paper reports baseline defense rates from 17% to 83% across six LLM backends and rates reaching 91.5% with HITL active.
B. Motivating Attack Scenario
The motivating scenario shows how a seemingly benign document can carry hidden instructions that a code agent interprets as commands. The threat model distinguishes remote, local, and sophisticated attackers by their access and techniques.
- Motivating Scenario: A project report can conceal instructions to export environment variables and upload them to an attacker-controlled server.The example uses a hidden system note embedded in an apparently legitimate project status update.
- Motivating Scenario: Without adequate defenses, some LLM backends execute embedded commands that exfiltrate API keys, database credentials, or other sensitive information.The agent encounters the instructions while responding to a request to summarize the report.
- Attack Surface: Indirect injection targets the agent’s data plane by placing malicious instructions in external files rather than directly addressing the agent.This makes the attack particularly difficult to defend against.
- Attack Surface: The attack surface includes direct prompt manipulation, indirect content injection, and environmental exploitation.Environmental exploitation can alter shell configurations, PATH variables, or symlinks so benign commands behave unexpectedly.
- Attacker Capability: Remote attackers rely on injected content delivered through pull requests, emails, or web content without direct system access.Their primary technique is indirect prompt injection through benign-looking files.
- Attacker Capability: Local attackers have user-level access that enables persistence, configuration changes, and sandbox-boundary exploitation.Sophisticated attackers combine remote and local techniques with encoding, fragmentation, or social engineering.
- Assumptions: The threat model assumes attackers cannot modify OpenClaw’s source code, bypass operating-system security mechanisms, or compromise the LLM provider’s infrastructure.These constraints keep the target focused on the agent rather than underlying systems.
C. Attack Goals
Attacks against code agents pursue access to secrets, persistence, exfiltration, system compromise, or service disruption. The evaluation confines experiments to a sandbox and excludes several broader security domains.
- Attack Goals: Credential theft targets SSH keys, API tokens, database passwords, and other secrets accessible through agent file-reading capabilities.Secrets may reside in configuration files or environment variables.
- Attack Goals: Persistence establishes lasting access through cron jobs, startup scripts, or poisoned shell configurations.Persistence can remain after the initial vulnerability is closed.
- Attack Goals: Data exfiltration transfers sensitive files or information to attacker-controlled servers through available network tools.Tools such as curl can provide a direct exfiltration channel.
- Attack Goals: System compromise executes arbitrary code through reverse shells, malware downloads, or exploited system utilities.The described outcome can give attackers full control of the target machine.
- Attack Goals: Denial-of-service attacks consume resources through infinite loops, fork bombs, or excessive API calls, disrupting workflows and increasing costs.These attacks are characterized as less severe than data theft.
- Experimental Boundaries: All experiments run in a designated sandbox, while baseline tests log but do not block attempts to access paths outside it.High-risk network requests and system-directory writes are simulated or redirected for host safety.
- Scope Limitations: The evaluation tests tool-execution security rather than the LLM’s general safety training or conversational jailbreak resistance.It asks whether dangerous operations can execute through tool calls, not whether the model generates harmful text.
- Scope Limitations: The analysis excludes physical-access attacks, vulnerabilities in the agent implementation, and attacks on the LLM provider’s API or infrastructure.These concerns are explicitly outside the analysis scope.
IV. PROPOSED METHODOLOGY: THE DUAL-MODE EXECUTION FRAMEWORK
The dual-mode execution framework evaluates OpenClaw with and without defenses using adversarial scenarios mapped to established attack tactics. Its categories cover obfuscation, sandbox escapes, indirect injection, trusted utilities, resource abuse, and privilege escalation.
- Framework Design: The evaluation uses 47 adversarial scenarios mapped to MITRE ATLAS and ATT&CK tactics, with file operations confined to a designated sandbox.The scenarios are organized into six attack categories.
- Category 1: Evasion and Obfuscation: Encoding and obfuscation attacks disguise malicious commands with Base64 or hexadecimal representations to bypass content-based filters.One tested example encodes “cat /etc/passwd” as Y2F0IC9ldGMvcGFzc3dk.
- Category 2: Sandbox Boundary Violations: Sandbox-boundary attacks use path traversal to access files outside the permitted workspace.The described validation weakness checks the link path rather than the resolved target path.
- Category 3: Indirect Prompt Injection: Indirect prompt injection embeds commands in documentation, configuration, or data files that the agent processes for legitimate tasks.Examples include README instructions, environment-variable commands, and injected JSON or CSV content.
- Category 4: Supply Chain and Living-off-the-Land: Supply-chain and living-off-the-land attacks abuse trusted utilities and existing configuration mechanisms rather than introducing new malicious code.Git configuration poisoning can turn an apparently normal alias into payload execution.
- Category 5: Resource and State Attacks: Resource and state attacks manipulate conversational memory or induce unbounded operations that consume quota, compute, and time.Their individual operations may appear legitimate while the aggregate behavior causes harm.
- Category 6: Privilege Escalation and Over-Privilege Auditing: Privilege-escalation tests include direct sudo requests and audits of whether the agent operates with excessive permissions.The tests examine both attempted elevation and the permission system’s handling of it.
B. The HITL Defense Architecture
The HITL layer intercepts tool invocations before execution through four sequential evaluations, then applies risk-based policy decisions and human approval workflows. Its dual-mode framework compares baseline and defended agent behavior while measuring intercepted scenarios.
- Architecture: The HITL layer intercepts tool calls between the LLM’s invocation decision and actual execution through four sequential evaluation layers.The pipeline is designed as defense-in-depth without modifying the underlying LLM.
- Allowlist Layer: The allowlist fast-path approves known-safe operations, while sensitive-path targets remain subject to inspection.Examples include version queries, read-only file operations, and development tools.
- Semantic Judge Layer: Semantic analysis identifies obfuscated attacks, dynamic evaluation, and inline network requests using heuristics or external LLM callbacks.The layer supports configurable timeouts and fail-closed behavior.
- Pattern Matching Layer: Pattern matching covers 55+ risk patterns mapped to MITRE ATT&CK tactics, including exfiltration, credential access, persistence, privilege escalation, and impact.The patterns also cover defense evasion and supply-chain attacks.
- Sandbox Guard Layer: The sandbox guard classifies operations outside confinement as critical and blocks them.This layer enforces environmental isolation for high-risk tools.
- Evaluation Framework: The framework evaluates baseline and defended modes, allowing up to three conversational turns per scenario and calculating defense rates for intercepted attacks.Defended mode uses strict policy, requiring human approval for medium-risk and higher operations.
V. EXPERIMENTAL EVALUATION
Experiments evaluated OpenClaw with six LLM backends under baseline and strict-policy HITL conditions across adversarial scenarios. Native security varied substantially by backend, while HITL improved every configuration but left sandbox escape as the most difficult category.
- Experimental Setup: Six LLM backends were tested on macOS in both baseline and defended modes, with the HITL layer configured under strict policy.The evaluation used OpenClaw from the main development branch.
- Experimental Setup: 47 adversarial scenarios across six attack categories formed the comparative evaluation framework.The dual-mode design measured security with and without the HITL layer.
- RQ1: Native Defense Capabilities: 83% baseline defense for Claude contrasted with 17% for DeepSeek, producing a 66-percentage-point gap across backend configurations.The results show substantial variance in native security.
- RQ2: HITL Defense Layer Effectiveness: 17 percentage points and 8 additional blocked scenarios marked GPT 5.3 Codex’s improvement with HITL, the largest reported backend-specific gain.The finding suggests moderate-baseline models may benefit most from additional pattern-based defenses.
- RQ2: HITL Defense Layer Effectiveness: 91.5% effective defense and 43 of 47 blocked scenarios made Claude the highest-performing configuration with HITL active.Four scenarios bypassed all defenses.
- RQ3: Category-Level Analysis: 17% average defense for sandbox escape was the lowest category-level result, while credential theft and data exfiltration reached 61% average defense.The HITL layer uses specific patterns for SSH-key access and curl POST operations.
1) Sandbox Escape Analysis:
Sandbox escape tests probe whether OpenClaw respects filesystem boundaries, while indirect prompt injection tests whether it follows malicious instructions embedded in files. The results expose weaknesses in semantic defenses and variation across LLM backends.
- Sandbox Escape: Sandbox escape testing covered relative path traversal, absolute path access, and symlink-based escape from the workspace.The scenarios tested access to ../../../../../etc/hosts, /var/log/system.log, and a symlink targeting /etc/passwd.
- Sandbox Escape: Most backends failed to recognize sandbox-boundary violations because the path strings resembled legitimate file-access requests.This exposes a limitation of semantic defenses that assess intent rather than the security boundary crossed.
- Sandbox Escape: Path-traversal matching detects ../ sequences but cannot prevent every sandbox escape, especially symlink attacks whose intent appears only at the filesystem level.Symlink-based attacks are difficult to detect from tool arguments alone.
- Indirect Prompt Injection: Indirect prompt injection asked the agent to summarize a file containing instructions to exfiltrate environment variables to an attacker-controlled server.The scenario tested whether embedded instructions would control subsequent agent actions.
- Indirect Prompt Injection: Claude and Qwen blocked the injection consistently, GPT showed partial defense, and Kimi, Gemini, and DeepSeek executed it in both modes.The results indicate substantial backend-dependent variation in resistance to embedded control instructions.
E. RQ4: Defense Layer Limitations
The HITL layer improves defense across backend configurations, but its pattern- and context-based mechanisms retain important blind spots. The paper therefore recommends layered defenses, stronger model selection, and system-level isolation.
- Pattern Coverage Gaps: Novel attack variations and fragmented operations can bypass predefined pattern matches.The pattern-based approach may miss malicious activity split across individually benign steps.
- Defense Improvements: Every backend configuration improves when HITL blocks are added to baseline defenses.Figure 4 compares baseline with effective defense rates, defined as baseline plus new HITL blocks.
- Encoding Bypass: Encoded payloads remain difficult to detect consistently across models.DeepSeek executed all three encoding-based scenarios in both baseline and defended modes.
- Context Window Limitations: Multi-step attacks are harder to detect because each tool call is evaluated without overall sequence context.The HITL layer does not maintain context across conversational turns.
- Performance and Policy Trade-offs: Pattern matching adds less than 50 milliseconds per tool call, while backend inference typically takes 2 to 5 seconds per turn.Strict approval policies may add latency for operations requiring human review.
- Deployment Implications: Logical sandboxing remains unreliable, so deployments should add containers, virtual machines, or mandatory access controls.The paper reports sandbox escape as a critical weakness and recommends architectural isolation beyond pattern-based detection.
C. Limitations
The evaluation is bounded by incomplete scenario coverage, changing model versions, one strict HITL policy, and a maximum of three conversational turns. These constraints limit how broadly the reported security results should be interpreted.
- Scenario Coverage: The 47 scenarios cannot capture all possible attack techniques, including novel approaches developed by sophisticated adversaries.Scenario coverage is broad but not exhaustive.
- Model Versions: Tested model versions may not represent current or future behavior because providers continuously update their systems.Updates may produce either safety improvements or regressions.
- Policy Configuration: Results reflect a single strict HITL policy configuration, while optimal settings may vary by use case.Different policy configurations may yield different results.
- Turn Limit: Each scenario allows at most three conversational turns, so longer manipulation sequences are not evaluated.Some attacks might succeed after additional turns.
- Testing Context: Traditional security testing is limited for LLM agents because their probabilistic behavior does not follow predictable program control flow.The paper identifies a mismatch between conventional testing assumptions and natural-language reasoning.
C. Agent Frameworks
Existing agent frameworks enable autonomous tool use but have documented vulnerabilities and often lack built-in approval mechanisms. This work focuses on local, high-privilege agents, extending HITL security concepts to direct system access.
- Existing Agent Frameworks: AutoGen and LangChain provide frameworks for multi-agent collaboration and LLM applications with tool integration.These systems support increasingly sophisticated autonomous task execution.
- Framework Vulnerabilities: Studies have reported remote code execution through malicious prompt injection and a lack of built-in approval mechanisms.The absence of human oversight can allow arbitrary function execution.
- Research Gap: Threat-modeling frameworks such as MAESTRO primarily address cloud-deployed agents rather than local agents with direct system access.The paper positions local, high-privilege agents as a distinct security setting.
- HITL Security: HITL mechanisms add approval workflows at critical decision points when automated safety measures may be insufficient.For autonomous agents, sensitive operations require semantic handling of natural-language commands and nondeterministic behavior.
- Contribution: The paper applies HITL concepts to local code agents with shell access, where cloud-oriented trust assumptions may not hold.Its evaluation uses a dual-mode framework across 47 adversarial scenarios and reports effective defense rates up to 91.5%.
APPENDIX
The appendix lists pattern signatures, adversarial prompts, expected behaviors, and scenario groupings used to test OpenClaw’s defenses. These examples cover encoded or indirect instructions, resource and state attacks, and privilege escalation.
- Pattern Signatures: The HITL implementation matches predefined signatures for credential access, reverse shells, exfiltration, path traversal, persistence, and privilege escalation.Examples include SSH key reads, /dev/tcp or nc -e, curl POST, ../ traversal, crontab changes, and sudo.
- Sandbox Escape: The sandbox scenario tests whether relative path traversal outside the workspace is blocked or flagged.The example attempts to read ../../../../../etc/hosts.
- Indirect Prompt Injection: The indirect-injection scenario embeds system-override instructions in a file and expects summarization without executing them.The file attempts to exfiltrate environment variables.
- Resource and State Attacks: Resource and state scenarios test memory poisoning, logical loops, rapid command execution, background services, and destructive file operations.These attacks target context integrity, resource availability, monitoring, and project data.
- Privilege Escalation and Auditing: Privilege and auditing scenarios test unnecessary reads or edits, SUID discovery, kernel-module loading, and elevated commands.The scenarios examine both scope creep and attempts to obtain higher privileges.