arXiv:2611.06039cs.CRNov 2026

Manuscript Offprint

arXiv:2611.06039

Securing Web Agents with the Compile-Then-Execute Paradigm

Annabella Chow, Jinhao Zhu, Sylvie Venuto, Abdulaziz Alharbi, Basel Alomair, Raluca Popa, David Wagner, Julien Piet

Annabella Chow UC Berkeley

Jinhao Zhu UC Berkeley

Sylvie Venuto UC Berkeley

Abdulaziz Alharbi KACST

Basel Alomair KACST

Raluca Popa UC Berkeley

David Wagner UC Berkeley

Julien Piet UC Berkeley

Abstract

Web agents commonly follow the ReAct paradigm, selecting each action from runtime observations that inherently mix trusted and untrusted content. This design makes their control flow vulnerable to prompt injections embedded in webpages. We introduce Baya¹, a compile-then-execute web agent designed to prevent prompt-injection-driven control-flow hijacking by design. Before accessing the live website, Baya compiles the user's request into an executable Python program that calls a Trusted Website API. The planning model does not observe live website content; only the compiled program processes it. Untrusted data may determine program values or select among branches defined during compilation, but it cannot redefine the user task or cause the model to synthesize new website operations at runtime. The Trusted Website API gives the compiler a unified view of the website's action space, enabling ahead-of-time planning without the stepwise action discovery required by reactive agents. Our evaluation across 581 valid WebArena Verified tasks shows that Baya achieves 77.8% aggregate utility, outperforming browser-only ReAct (55.1%) and API-enabled ReAct (66.7%). On WASP, a security benchmark for web agents, Baya achieves 0% attack success rate, compared with 16.2% for API-enabled ReAct and 25.5% for browser-only ReAct.

1 Introduction

Web agents have emerged as a promising interface for automating complex web tasks, such as retrieving information, shopping online, or planning travel. Modern web agents typically operate in a reactive loop: they observe the current webpage, reason about the next action, execute it through a browser interface, and repeat until the task is complete [37]. This ability to adapt to information revealed during execution

enables agents to operate on dynamic websites and complete complex, multi-step tasks.

The same adaptability creates a fundamental security risk. Unlike traditional software interfaces, webpages inherently contain a mixture of trusted and untrusted information, including content from the website itself, users, and third parties. When a reactive agent incorporates this content into its reasoning, attacker-controlled content can influence not only the data it processes but also the actions it selects. This opens the door to indirect prompt-injection attacks [10, 38], in which malicious web content can cause the agent to deviate from the user's intended task and perform attacker-chosen actions [33]. In this paper, we focus on preserving control-flow integrity: preventing untrusted web content from introducing attacker-chosen operations beyond the user's intended workflow.

Separating planning from execution and committing to a pre-compiled plan provides a structural defense against control-flow hijacking. Instead of allowing the agent to continuously decide its next action based on runtime webpage content, the agent first compiles a task-specific plan and then carries out that plan against the web. In this architecture, information retrieved from webpages is treated as runtime data consumed by a compiled plan, rather than as instructions that can arbitrarily redefine the agent's control flow. Prior work, such as CaMeL and FIDES, has demonstrated that compile-then-execute is an effective foundation for secure tool-calling agents [1,8,9,20]. A prior analysis of WebArena found that all benchmark tasks are compatible with this paradigm, assuming complete trusted APIs [28]. However, applying compile-then-execute to web agents is more challenging than to conventional tool-calling agents.

First, compile-then-execute requires knowledge, before execution, of which operations are available and what they mean. This is typically available to tool-calling agents through predefined and documented tool interfaces. In contrast, web agents must interact with heterogeneous websites whose operations and semantics may be undocumented, incomplete, or difficult to determine in advance. Most websites do not expose complete, documented, and semantically meaningful APIs

¹Baya is named after the Baya Weaver, a Southeast/South Asian native bird known for building intricate hanging nests that protect eggs and chicks, a parallel to our compile-then-execute design, which constructs a secure plan before execution.

for all actions available through their user interfaces. As a result, there is a missing abstraction between today's web infrastructure and the stable semantic interface required by a compile-then-execute agent.

Second, even when trusted website APIs are available, there typically is little or no documentation of their semantics, dependencies, and site-specific rules. As a result, the agent must discover these rules, catch failures, diagnose their cause, and adapt the plan securely. Past work typically focuses on “one-shotting” the plan, but we’ve found that web agents must revise and repair failing plans, which is challenging to do securely.

In this paper, we introduce Baya, a web agent based on the compile-then-execute paradigm that addresses these challenges for tasks whose workflows can be determined before execution. During compilation, the agent emits an executable program, fixing its control flow and possible API interactions before live execution begins. Runtime data may fill program variables or select among branches defined during compilation, but it cannot introduce new task instructions.

Baya consists of three main components. First, we take a first step toward understanding what API abstractions are sufficient for web agents by manually constructing a Trusted Website API that presents native REST endpoints and wrappers for UI-only functionality through a unified, documented interface augmented with site-specific execution constraints and prerequisites. This interface is prepared for each website before user tasks are processed; automating its construction remains future work. Second, a sandboxed coding agent compiles the user's task into a Python program and validates it using mocked tests without accessing the live website. A catalog of available APIs, search tools over this catalog, and site-specific guidance help Baya find the relevant operations and write a program that uses them correctly. Third, an isolated execution engine runs the program against the live website. If execution fails, it exposes restricted diagnostic feedback to help the compiler repair the program. Feedback is restricted to prevent it becoming a channel for attack.

By separating task compilation from runtime web interaction, Baya limits the ability of untrusted webpage content to alter the agent's intended control flow while retaining the ability to consume web data during execution. Outcome manipulation and general data-flow security are outside our scope. Beyond security, Baya improves utility by providing a structured view of the website's available operations, reducing uncertainty about how to accomplish the user's task.

We evaluate Baya along three dimensions: utility, security, and efficiency. We measure task completion using WebArena Verified [12], a manually audited revision of WebArena [42]. We compare Baya to two simple ReAct agents (ReAct_web + API and ReAct_web) and to Untrusted Content Masking (UCM), a secure ReAct-style web agent that masks and quarantines untrusted content [25], and evaluate latency and execution cost. To assess security, we evaluate Baya on

Table 1: Overview of utility, security, and efficiency. Utility is averaged over four environments, security over two.

SystemUtility ↑ASR ↓Latency (s) ↓
Baya77.8%0.0%327.15
ReAct_web + API66.7%16.2%86.60
ReAct_web55.1%25.5%59.91
UCM²75.3%0.0%469.04

WASP [13], measuring its robustness against prompt-injection attacks embedded in web content. Across four environments, Baya has the highest aggregate utility with all three models, outperforming ReAct_web + API and ReAct_web by 11.1 and 22.7 percentage points, respectively. On GitLab, Baya also outperforms UCM by 17.6 percentage points. Moreover, Baya achieves 0% observed intermediate and end-to-end ASR on WASP, compared to the ReAct baselines' aggregate ASRs of 16.2% and 25.5%, respectively.

References (37)