Compiling web agents ahead of time blocks page injection
Reviewing Securing Web Agents with the Compile-Then-Execute Paradigm · Annabella Chow, Jinhao Zhu, Sylvie Venuto et al.

Researchers build a web agent that turns each request into a program before it ever sees the live site, so instructions hidden in webpages cannot add new actions. It blocks every control-flow hijack on a security benchmark, but the trust moves into a hand-built API, and attacks that steer outcomes remain.
A web agent opens a product page. Buried in a review is a line telling it to do something the user never asked for. In most agents, the model reads that line and picks its next move with it in view. In Baya, the model that plans the task never sees the page at all.
The usual design is a loop: look at the page, choose an action, look again. Every decision is made with untrusted page text sitting next to the user's request. So a well-placed sentence on a webpage can act as a new instruction, and the agent invents an operation on the spot. That is the attack.
The researchers reverse the order. Before touching the live site, Baya turns the user's request into a Python program. The program calls a curated, strongly typed API for that website, with each operation's inputs, outputs and failure cases written down in advance. It is tested against mocked responses, then handed to a separate engine that runs it against the real site.
Page content can still fill in values or choose which branch runs. It cannot add a branch. Any model calls at runtime are narrow, data-only jobs on results already fetched, such as picking between candidates. None of them can create a new website operation.
None of this is a new principle. Deciding control flow before you read attacker input is the old separation of code and data. What is new is applying it cleanly to an agent, and the results are strong. On a web agent security benchmark, Baya had no successful hijacks, against roughly a quarter for a standard browser agent. What surprised me is that it also finished more tasks: 77.8% against 55.1%. Planning against a clean, typed API means fewer choices to get wrong at each step.
The attack surface moves upstream
That zero is a claim about control flow, and the researchers say so. Steering the outcome within permitted branches is out of scope. If the program branches on review scores, a poisoned review can still change which product gets chosen. Data-flow attacks are not covered either.
Trust also moves somewhere new. The website API is built by hand, and the researchers built it themselves for the benchmark sites. Whoever controls that API, or the site operator behind it, sits inside the trusted base. API error messages that echo site content could leak into compilation if onboarding is careless. And the benchmark uses a fixed set of injections. I would want to see an attacker who knows the design and aims straight at the branches.
There is a price too. It is slower and burns more tokens, and it cannot handle tasks whose steps must be discovered from the page itself. I still think the design is right. The injection can still choose a road. It can no longer build one.
Further analysis
Problem
The paper studies prompt-injection risks in web automation agents that follow the reactive ReAct style, where the model repeatedly observes mixed trusted and untrusted webpage content while deciding each next action. This makes control flow vulnerable to attacker-controlled content that can induce the model to synthesise new, unauthorised operations at runtime. Preserving control-flow integrity for web agents is important because such agents typically act with user privileges and can be coaxed into performing sensitive actions unless the planning process is isolated from untrusted inputs.
Approach
The authors present Baya, a compile-then-execute web agent. Before touching a live site, Baya uses an LLM-backed coding harness to compile the user goal into an executable Python program that calls a Trusted Website API. The planning model never observes live website content; only the compiled program consumes runtime data. The Trusted Website API is a curated, strongly typed surface that unifies backend REST endpoints and trusted browser automations under machine-readable contracts describing signatures, preconditions, postconditions and error domains. Compilation includes mocked unit tests. A separate, isolated execution engine runs the program against the live site and returns restricted diagnostics on failures to permit secure replanning. Runtime LLM use is allowed only in narrowly scoped, data-only calls on already retrieved candidates.
Key Findings
- Baya substantially improves task utility on WebArena tasks. Across 581 valid tasks the paper reports an aggregate utility of 77.8%, with per-model completion rates of 81.9% for Claude Sonnet-4.6, 78.5% for Gemini-3.5-Flash, and 72.8% for GPT-5.6-Luna. These results exceed browser-only ReAct and API-enabled ReAct baselines.
- Baya strongly reduces prompt-injection-driven control-flow hijacking. On the WASP security benchmark Baya achieved 0% observed attack success rate, versus 16.2% for API-enabled ReAct and 25.5% for browser-only ReAct in the reported aggregates, and showed 0% intermediate and end-to-end ASR across evaluated models and environments.
- Baya sometimes increases success because precompiled programs and focused typed APIs reduce decision complexity compared with reactive agents that must choose among UI and API actions at each step. However, Baya incurs higher latency and token cost: the Python-based implementation averaged higher model usage, greater monetary cost and longer per-task runtime than ReAct baselines, though still faster and cheaper than one compared security-oriented masking approach in the paper.
Limitations
Baya protects only against control-flow hijacking; outcome manipulation and general data-flow attacks are out of scope. It requires a trusted, functionally complete Trusted Website API prepared ahead of use, and the current study manually constructs these APIs for the benchmark sites. The paradigm cannot support tasks whose required workflow must be discovered from untrusted runtime content. Compilation and validation cannot anticipate undocumented live-site constraints, so failure-driven replanning is necessary and limited. Baya also increases latency and model token consumption compared with reactive approaches.
Implications
Offensive implications shift under Baya. Prompt injections embedded in pages cannot force a Baya agent to create new API calls or alter control flow at runtime, removing a powerful attack class. Attackers may instead aim to influence task outcomes within permitted branches, exploit reflected content in API error messages to influence compilation if onboarding is unsafe, target the compilation or API construction pipeline, or attempt to compromise the Trusted Website API or site operators who are in the trusted computing base. Narrow runtime LLM calls remain a limited surface for manipulation of semantic outputs but cannot synthesize new website operations.
The paper title, authors and abstract
Securing Web Agents with the Compile-Then-Execute Paradigm
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.


