AI Operating Computers: The Paradigm Shift from Batched Instructions to Code Execution
How computer-use agents are moving from screenshot-and-click GUI interaction to generating executable programs, why conditional logic, loops, and result verification change how agents handle complex tasks, and engineering practices—including dynamic target enumeration, read-back verification, and coverage reconciliation—that prevent silent incomplete execution.
1. Background: From Screenshots and Clicks to Programmatic Control
Over the past few years, most research and applications of computer-use agents have followed one default approach: the system takes a screenshot, the model identifies UI elements in the image, and then outputs instructions such as click coordinates, keystrokes, and text input. This is commonly called GUI-only interaction. Its advantage is universality—in theory it works with any software. Its drawback is that every step depends on visual understanding of the interface, so even minor UI changes can cause errors.
In the past year or two, more and more model providers have recommended a different approach in their official documentation: let the model directly generate an executable program that uses general-purpose desktop or browser automation libraries, mixing UI operations with ordinary program logic. This looks like a mere implementation detail, but it actually changes the interaction logic between the agent and its environment—it determines whether the model can perceive intermediate results and adjust its actions accordingly.
2. The Essential Difference Between Two Execution Paradigms
2.1 Batched Actions
The model outputs a fixed sequence of instructions in one shot, such as “click input field A, type text B, click button C.” All instructions are fully determined at generation time. During execution, the system runs them in order and never changes later steps based on intermediate results.
The core characteristic here is “plan before execution.” Once the plan is generated, the executor can only follow it literally.
2.2 Code Execution
The model outputs a real program that can contain three kinds of control structures:
- Conditional branching: if a dialog appears, close it; if a field is empty, skip it.
- Looping: apply the same filling procedure to every row in a table.
- Result verification: after writing, read the state back to confirm the value was actually saved.
The next action is decided at whatever point the program has reached during execution. This is “decision-making during execution,” in contrast to the “decision-making before execution” of batched actions.
2.3 Comparison
| Dimension | Batched Actions | Code Execution |
|---|---|---|
| Decision timing | Determined once at generation time | Determined step by step at runtime |
| Conditional branches | Hard to express; requires manual predefinition | Directly expressed with conditional statements |
| Batch processing | Each item must be expanded into instructions | Loops handle any number of items |
| Result verification | Relies on the model’s self-assessment | Program can read back and assert |
| Error handling | Continues even when preconditions fail | Can catch exceptions and branch |
| Auditability | Instruction lists are easy to read | Code requires review, but logic is complete |
3. An Intuitive Analogy
Imagine asking an assistant to update qualifying customer records from a batch of files into a business system, one by one.
With batched actions, you must write a detailed checklist in advance specifying every click and every input. The assistant can only follow it. Even if the precondition of step three (e.g., “the record status is pending”) no longer holds, the assistant keeps going, because the checklist is fixed.
With code execution, you only give rules: open each record, check its status field, update it if pending, skip it if already processed, and summarize the results at the end. The rules themselves contain judgment and iteration, so the executor can act based on actual conditions.
The difference between the two approaches is not which one is smarter, but whether the task description includes the ability to respond to runtime state.
4. Why Complex Tasks Depend More on Programmatic Control
In real desktop and web tasks, the following situations are extremely common:
- Uncertain UI state: loading speeds vary, dialogs appear randomly, and the same button’s position changes with window size.
- Variable task scale: the number of table rows or pending items is unknown in advance.
- Intermediate results affect subsequent actions: the output of one step determines the input of the next.
- Failures need localized recovery: retry only the failed item rather than restarting the whole workflow.
Batched actions struggle to cover these cases. Either every branch must be expanded in advance—causing instruction bloat—or branching is abandoned, relying on manual inspection afterward. Code execution covers these variations with just a few control structures.
5. A Typical Hidden Failure: Silent Incomplete Execution
In one experiment, a task required answering 125 questions on a worksheet. The model generated a program that ran successfully and reported “85 questions completed”—the output looked logically complete. The problem was that the loop’s row range covered only part of the data; the remaining 40 questions were never scanned. More critically, the model never noticed the omission.
An alternative approach first wrote a generic solving function, validated it against known samples, then dynamically identified all qualifying question rows in the worksheet—and completed all of them. The difference was not solving ability, but whether task coverage was verified.
The hallmark of this type of error is that the program does not crash, the output looks reasonable, but the result is incomplete. It shows that whenever a task involves batch processing, “coverage” must be treated as an independent check.
6. Engineering Best Practices
6.1 Define the Generic Solving Unit First, Then Wire It into the Batch Flow
Encapsulate the processing logic for a single record into a standalone function and validate it against known samples. Only after the unit is confirmed correct should it be placed inside a loop. This separates “logic errors” from “iteration errors” during debugging.
6.2 Enumerate Targets Dynamically Instead of Hardcoding Ranges
The target set should be queried at runtime based on conditions, with its count recorded. Below is an illustrative example where interface names are used only to convey the idea:
def process_records(sheet, rule):# Dynamically enumerate all data rows instead of hardcoding a row rangerows = sheet.list_rows()targets = [r for r in rows if rule.match(r)]done, failed = [], []for row in targets:try:answer = solve_one(row) # Generic single-record handlersheet.write(row.index, answer)if sheet.read(row.index) == answer: # Read-back verificationdone.append(row.index)else:failed.append((row.index, "read-back mismatch"))except Exception as exc:failed.append((row.index, str(exc)))# Coverage reconciliation: processed count must equal target countassert len(done) + len(failed) == len(targets)return {"total": len(targets), "done": done, "failed": failed}
Three key points in the code: targets are generated dynamically by query; every write is verified by reading back; and coverage is reconciled at the end. If reconciliation fails, the program should raise an error rather than output a seemingly complete result.
6.3 Cross-Check with Independent Counts
Before the task starts, independently count how many items should be processed from the source data—for example, total rows or the number of qualifying records. After execution, compare the processed count against this figure. If they differ, the workflow should stop and report the discrepancy in detail.
6.4 Retry Failures Locally
Record failed items separately and re-run only those. This avoids duplicate writes caused by re-running the entire flow and makes problems easier to locate.
6.5 Constrain the Execution Environment
Programmatic control is more powerful—and riskier. Run it in an isolated environment, grant only the minimum permissions needed to complete the task, and log every operation for auditing and traceability.
7. Applicability Boundaries and Risk Control
Code execution is not superior in every scenario. Extra caution is needed in the following cases:
- Irreversible operations: deletion, sending messages, payments, permission changes—user confirmation should be obtained before execution.
- Ambiguous targets: if the decision criteria are ambiguous, clarify the rules first rather than letting the program guess.
- Extremely simple UIs: for operations that take only one or two steps, batched actions are more direct; introducing extra program structure is unnecessary.
Additionally, if the program processes external data, inputs should be validated to avoid directly concatenating unchecked content into commands or query statements.
8. Conclusion
The shift of computer-use agents from “look at the screen and click” to “write a program to operate” fundamentally moves decision timing from before execution into execution itself. Conditional branching, looping, and result verification enable agents to handle uncertain interfaces and variable task scales.
But programmatic control also introduces new failure modes. Silent incomplete execution shows that a program running successfully does not mean the task is complete. Developers should treat validation of the generic solving unit, dynamic enumeration of targets, read-back confirmation, coverage reconciliation, and localized retry as standard practice—and keep a human confirmation step before irreversible operations. Only then can automation efficiency and result reliability be guaranteed at the same time.
