Computer-Use Agents: From Clicking to Coding with Code Execution
This article compares two approaches to computer-use agents: batched GUI actions and code execution. It explains why code execution can prevent silent omissions in tasks such as spreadsheet processing. It also outlines a layered design framework for reliable agents and evaluation metrics that measure completion and whether the agent can detect its own errors.
1. A Typical Failure Scenario
Imagine an agent tasked with completing 125 questions in a spreadsheet and filling in the answers. The agent generates a program that looks well structured, with loops and encapsulated functions. When it runs, it confidently reports “85 questions calculated.” The rows covering the remaining 40 questions were never traversed. More subtly, the agent is entirely unaware of the omission.
Another approach takes a different path. It first writes a general-purpose solving function and checks its correctness against a few known samples. Then it dynamically scans the spreadsheet, identifies every row that meets the criteria, completes all of them, and verifies each result.
The difference lies not in how “smart” the model is, but in the methodology of task execution. This shift is the most notable development in current research on computer-use agents.
2. The Fundamental Difference Between Two Interaction Paradigms
Over the past few years, the mainstream approach to computer-use agents has been pure graphical user interface (GUI) interaction. The agent captures a screenshot, lets the model interpret the image, and then outputs the next click coordinates or keystrokes. Two execution modes have emerged from this approach.
1. Batched Actions
The model generates a fixed sequence of operations in one pass, such as “click A, type B, click C.” All instructions are determined at generation time, and the sequence cannot adjust to intermediate feedback during execution. This is like handing an assistant a fixed checklist. Even if the precondition for step three no longer holds, the assistant keeps following the list mechanically.
2. Code Execution
The model writes an actual program that combines interface operations with program logic. The program can include:
- Conditional checks: Close a pop-up if it appears, otherwise continue.
- Loops: Perform the same operation on every row in a table that matches a condition.
- Result verification: After an operation, check whether the status field actually changed to “Saved.” If not, retry or report an error.
The program decides the next step based on what it observes at each point in execution. This forms a perceive-decide-act loop rather than open-loop instruction playback.
3. How Code Execution Addresses Silent Omissions
Returning to the 125-question case, the failure has two root causes, and the code execution paradigm can handle both.
First, a static boundary assumption causes omissions. When generating code, the failed agent assumed a row range for the questions instead of detecting it at runtime. The correct practice is to write detection logic first, such as scanning the non-empty question cells in a given column. This way, the data range comes from runtime observation rather than generation-time guessing. This matches a core principle of experienced developers writing data-processing scripts: never hard-code a boundary that you can obtain at runtime.
Second, the agent lacks a completion check. After printing “85,” the agent declared the task finished. The workflow had no step comparing expected and actual results. In the code execution paradigm, each task can have an explicit completion criterion:
# Example: completeness checktotal = scan_target_rows(sheet) # Dynamically scan the number of rows to processdone = process_all(sheet, total) # Process all items and return the number completedassert done == total, f"Missed {total - done} items"
This structure of defining the criterion first, executing second, and verifying last upgrades the agent from an action generator to an executor accountable for its results.
Third, validate against samples before scaling. Testing the core function on a small set of official samples before applying it to the full dataset applies the idea of unit testing to agent task planning. This step costs very little, yet it catches many failures where the logic looks correct but produces systematic errors.
4. An Engineering Design Framework
Based on the analysis above, a reliable code-execution agent should include the following layers:
1. Task decomposition layer: Break the natural language goal into four stages: detect, plan, execute, and verify. Each stage produces intermediate results that can be checked.
2. Dynamic perception layer: Obtain all data boundaries, element positions, and status fields at runtime. Do not rely on static assumptions made at generation time.
3. Controlled execution layer: Run code in a sandboxed environment that restricts file system and network access. After each interface operation, read back the state to form a closed loop.
4. Verification and recovery layer: Define a completion criterion for each subgoal. When verification fails, retry a limited number of times. If the retry threshold is exceeded, escalate to a human instead of passing silently.
5. Observability and audit layer: Record execution traces, intermediate screenshots, and verification results in full to support root-cause analysis afterward. In enterprise deployments, these traces and logs can typically connect to general-purpose logging services and monitoring and alerting tools. For example, agent run logs can be stored in a cloud logging service with alerts configured for anomalies, which reduces operational overhead.
5. Evaluation Methods Must Evolve Too
This shift also requires updated evaluation methods. Traditional benchmarks often use single-step action accuracy as the main metric. That is acceptable for the batched action paradigm. For the code execution paradigm, the following metrics matter more:
- Task completion rate: Whether the final result was achieved, rather than whether the process actions looked human-like.
- Completeness ratio: The ratio of items that should have been processed to items actually processed. This metric specifically captures omissions.
- Self-awareness: Whether the number of completed items the agent reports matches the actual number completed. In other words, whether the agent can detect its own omissions.
- Robustness: Whether conditional branches work correctly when disturbances such as pop-ups or loading delays occur.
In comparative experiments across multiple models, a unified task set and a unified scoring script are especially important. They separate differences in methodology from differences in model capability and produce reproducible conclusions.
6. Conclusion
Moving from “give the model a screenshot and let it guess where to click” to “have the model write a program with conditions, loops, and verification” is not a minor improvement to the toolchain. It is a fundamental shift in how agents interact with computers. The code execution paradigm brings into agent design several practices that software engineering has validated over decades: dynamic detection, unit testing, assertion checks, and retries on failure. For teams aiming to deploy agents in office automation, data processing, and systems operations, building verification and observability capabilities first often yields more predictable returns than pursuing a stronger base model.
