arXiv(opens in a new tab)cs.CRSep 2026Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:2609.01222

What's in Your Agent's Context? Context Privilege Escalation Attacks against AI Agent Harness

Zichuan Li, Jian Cui, Ashley Chen, Xiaojing Liao, Luyi Xing

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Zichuan Li, Jian Cui, Ashley Chen, Xiaojing Liao, Luyi Xing

University of Illinois Urbana-Champaign

{zichuan7, jiancui3, ajchen8, xjiao, lxing2}@illinois.edu

Abstract—Real-world, high-profile AI agent harnesses often rely on vendor-proprietary or opaque designs for context assembly, leaving the sources and underlying logic of assembled context poorly understood and the resulting security risks largely unexplored. In this paper, we present the first systematic analysis of context assembly designs in real-world AI agent harnesses. We study and uncover how an agent harness is designed to collect and assemble context from diverse sources, and identify a set of practical attack vectors arising from these designs. Our analysis brings to light two novel categories of attacks in the context assembly of real-world harnesses: (1) Message-Role Context Privilege Escalation (M-CPE), which occurs when attacker-controlled content originating from a low-privileged context is incorporated into a higher-privileged message role. (2) Cross-Scope Context Privilege Escalation (X-CPE), which occurs when attacker-controlled content persists beyond the context in which it was introduced. We performed a systemic security analysis of the CPE attacks against 12 real-world agent harnesses, including Claude Code and Codex. The resulting consequences include full agent compromise, remote code execution, denial of service, and manipulated tool or skill invocations.

I. INTRODUCTION

AI agents such as Codex, Claude Code, and Gemini CLI are widely used in AI-assisted software development, content creation and processing, scientific research, and various other workflows. Based on common terminologies, an “AI agent” includes both the AI model(s) and the harness [1], where an “agent harness” is the software code, configuration, and execution logic around an AI model. Real-world agent harnesses assemble contexts from heterogeneous sources, including user prompts, system instructions, the agent’s configuration, memory and history files, descriptions and metadata of third-party components (e.g., tools, skills, or services), and external contents returned by third-party components, etc. At runtime, the agent harness maintains the context and prepares it as input (also referred to as the “prompt”) for each subsequent call to the designated LLM.

Prior work showed that the external contents can include malicious instructions to LLMs, a widely recognized and practical threat referred to as indirect prompt injection [2], [3], [4], [5]. To mitigate indirect prompt injections, major providers such as OpenAI, Anthropic and Google each defined a set of privilege roles for instructions sent to LLMs, and state-of-the-art LLMs have been trained to prioritize instructions with higher privileged roles [6]. In particular, higher-priority roles are intended for instructions to carry safety and security policies and agent developers’ built-in instructions, whereas lower-priority roles are meant to carry third-party tools’ outputs, and LLM’s chain-of-thought, etc., which can be much less trusted [7]. For example, OpenAI defines five roles, namely system, developer, user, assistant and tool, which represent the privilege hierarchy and trust levels (from highest to lowest) that the model applies in case (1) there are conflicts between instructions of different roles, or (2) instructions with a low-privilege role tries to perform critical or highly risky operations. Correspondingly, in real-world agents’ harnesses, the context is composed of multiple segments, each labeled with a specific “role” while carrying contents and instructions. 1^{1}

Emerging security risks in agent context harness. We find that real-world, high-profile agents, however, often come with vendor-proprietary or opaque designs about context assembly mechanism and logic, with questions including (Q1) from which sources do the agent loads contents to context, (2) when and under what logic conditions are the sources loaded, and (3) what privileges roles does the agent assign to each source. By studying harnesses of 12 high-profile agents (e.g., Codex, Claude Code, OpenClaw, see Table I), we find that individual agents leverage a wide range of different sources of contents to assemble into context (e.g., various memory files from quite different directories, various directories to find and load skills descriptions, various configuration information, various environment information such as file-system directory tree and recent Git commit messages, detailed in § IV-A). In doing so, their agent harnesses often come with vendor-specific logic in selecting the contents to load (§ IV-D), and even wrapping the contents with opaque agent-specific syntax. Further, different agents' harnesses lack a transparent, uniform practices in assigning privileges roles to contents from different sources. We show that emerging design-level vulnerabilities or insecure practices in these agents' context harnesses are practically enabling adversarial contents from overlooked, heterogeneous context sources to enter agent context, as malicious instructions to the LLMs. Further, we find that the malicious instructions can exploit context harness logic and privilege role assignment in these agents to manipulate their privileges in agent context, directly jeopardizing security of real-world agentic systems with serious implications. Notably, prior research on indirect prompt injection mainly considered

1^{1}Similar to OpenAI [7], each segment in the context bearing a privilege role is called a “message” in this paper.

malicious instructions from particular content sources, especially contents provided by third-party tools or skills [8], [9], [10]. Significantly going beyond, a systematic security analysis of agent context harnesses, however, has never been done before, up to our knowledge.

Context privilege escalations exploiting context harness. We report two novel classes of privilege escalation attacks (§ III): (1) By exploiting harness designs, adversarial contents from a context source with a less trusted, low-privileged role (e.g., tool outputs, web contents) are able to propagate into higher-privileged context sources (e.g., skills, memory files, configuration files used by the agent), and get assembled into agent context in the higher role. This is called message-role context privilege escalation (M-CPE). (2) Similarly, the adversarial contents are propagated into a context source that is more persistent for the agent or has a boarder-scope impact. For example, malicious contents returned by third-party tools are only temporarily inside agent context and will be lost immediately after the agent is terminated or restarted. However, our attacks (§ IV) leverage a range of novel attack vectors to instruct the agent to store the malicious contents to a more persistent source (e.g., selected memory files or even directory names) that the agent is designed to use even after the agent is relaunched to process other projects. We call this cross-scope context privilege escalation (X-CPE).

We refer them both as context privilege escalation or CPE. The attacks are done in our study by exploiting exploiting harness designs of 12 high-profile agents, including Codex, Claude Code, OpenClaw, Gemini CLI, etc. (see the full list in Table I). We implemented proof-of-concept (PoC) end-to-end attacks against all these agents, which are empowered by state-of-the-art models including GPT-5.5, GPT-5.4-mini and DeepSeek-V4-Flash. Note that we reuse practical threat models that are widely recognized and accepted for agent security (§ II) and consider two separate categories of attackers: (1) indirect prompt injection attackers whose untrusted third-part contents (e.g., web contents or contents returned by third-party tools) can be processed by agents, and (2) third-party component attackers who release malicious third-party tools, skills, etc. (§ II-B).

Taxonomy of novel CPE attack vectors. To systematically analyze and achieve CPE attacks, we come up with a taxonomy of 16 novel attack vectors spanning three categories (Table II), as detailed in § IV.

Security analysis tool CoRA and exploits on real agents. To enable a systematic analysis of CPE vulnerabilities and exploitability in real-world agent harnesses, we designed and developed Context Risk Analyzer (CoRA). CoRA is an LLM-assisted analysis pipeline that is capable of (1) identifying context sources given an agent harness implementation including their privilege roles (based on static analysis of harness source code), (2) preparing context sources and context source-dependent execution environments, and actually running the agent harness to validate all reported context sources including their privilege roles, and (3) performing fully automatic PoC exploits by selecting relevant attack vectors

TABLE I: Harness of 12 high-profile agents we analyzed, all subject to our proof-of-concept end-to-end attacks

Agent HarnessVersionLanguageStars
Codex [12]0.120.0Rust78.6k
Claude Code [13]2.1.88TypeScript118.8k
Gemini CLI [14]0.39.0-nightlyTypeScript102.6k
Qwen Code [15]0.14.4TypeScript24.0k
Kimi CLI [16]1.33.0Python8.3k
Aider [17]0.86.3.devPython44.0k
OpenCode [18]1.4.3TypeScript151.0k
Cline [19]3.77.0TypeScript61.1k
Goose [20]1.30.0Rust38.0k
Pi-mono [21]0.67.68TypeScript41.6k
OpenClaw [22]2026.4.12TypeScript365.8k
Hermes Agent [23]0.9.0Python122.5k

from our generalized taxonomy to validate CPE vulnerabilities in the agent under analysis. (Table II). We run CoRA on 12 real-world agent harnesses and report 282 context sources vulnerable to CPE attacks. Our research shows that CPE practically enable attacks to (1) attack victim agents, such as manipulating agents' reasoning, actions, and task outcomes, and (2) obtain control over the victim agent's host machine, such as achieving remote code execution (RCE) [11].

Responsible disclosure and mitigation lessons. We reported all attacks to the vendors or maintainers of the 12 agent harnesses and are responsibly working with them to address or mitigate all problems we find. For example, we are discussing reducing attack surfaces by using less context sources, filtering out malicious instructions with CPE attempts, and making context harness design and practices more transparent (see lessons in § VII). Some vendors such as Codex and Gemini CLI have released new versions of agents to mitigate the threats.

Contributions. Our contributions are summarized as follows.

  • New understandings and novel attacks. We present the first systematic security analysis of agent context harness, specifically focusing on vulnerabilities in the design space of real-world agents' context harness. We introduce two novel classes of context privilege escalation attacks (CPE), systematically enabled by our taxonomy of 16 novel CPE attack vectors.

  • New techniques. We designed and implemented the first automatic technique CoRA that can fully automatically identify and end-to-end validate CPE vulnerabilities given harness implementation of state-of-the-art high-profile agents such as Codex, Gemini CLI, Claude Code, and OpenClaw. We will release full source code of CPE along with the paper.

  • Real-world results and lessons for defenders. We implemented end-to-end CPE attacks² against all 12 high-profile agents we studied, demonstrating that CPE generally affect all of them with serious security implications, bringing to light significant security gaps in the design space of real-world agent harness. Understandings and new insights that can

²See https://zichuan.li/LLMAgentCPE be derived from our study will be invaluable for defenders and open new avenue for research to elevate agent harness security.

References (53)