AI Agents Writing Code to Operate Computers: Capability Tiers and Deployment Risks

    AI models are increasingly moving beyond natural language comprehension to directly executing tasks within computer environments. These systems, known as AI agents, typically follow a workflow of abstracting tasks into functions, validating with samples, and batch executing. This article breaks down the three-step coding process of agents, classifies their capabilities into three tiers, and highlights key deployment risks alongside practical advice for developers.

    Why AI Agents Start by “Writing Code”

    Recent advancements in large language models (LLMs) have primarily focused on better natural language comprehension. However, the focus is now shifting toward enabling models to complete work directly within computer environments—such as reading and writing files, calling APIs, running code, and handling errors to deliver verifiable results. The industry refers to these systems as AI Agents. An agent typically involves perception, decision-making, and execution, progressively advancing tasks through multi-turn loops.

    Horizontal evaluations show that when faced with tasks like “processing all rows in a table that meet specific conditions,” capable models often adopt a common approach: write a general-purpose function first, validate it with provided examples, and finally iterate through the entire dataset for batch execution. The following analysis is based on the common characteristics of this approach rather than specific evaluation metrics.

    Three-Step Process: Abstraction, Validation, Batch Execution

    1. Abstracting the Task into a Function

    The problem with answering questions one by one is that each question relies on a new generation, making results difficult to reproduce. Once written as a function, the same input will always yield the same output. The determinism of code cannot eliminate all errors, but it concentrates them within the rules themselves, making them easier to inspect and modify.

    Here is an example. It relies on Python 3.10+, pandas 2.0+, and openpyxl 3.1+. The rules inside are placeholders and should be replaced for actual tasks:

    1. import pandas as pd
    2. REQUIRED_COLUMNS = ["Problem", "Input"]
    3. def check_columns(df: pd.DataFrame) -> None:
    4. missing = [c for c in REQUIRED_COLUMNS if c not in df.columns]
    5. if missing:
    6. raise ValueError(f"Missing required columns: {missing}")
    7. def solve_row(row: pd.Series):
    8. """Example rule: convert the 'Input' field to a number and multiply by 2. Replace with actual task rules."""
    9. try:
    10. value = float(str(row["Input"]).strip())
    11. except (ValueError, TypeError):
    12. return None # Leave rows that cannot be parsed empty for manual review
    13. return value * 2
    14. def run(path: str, sheet=0) -> pd.DataFrame:
    15. df = pd.read_excel(path, sheet_name=sheet, engine="openpyxl")
    16. check_columns(df)
    17. df["Result"] = df.apply(solve_row, axis=1)
    18. return df

    2. Validating with Samples

    Tasks usually come with a few sets of example inputs and expected outputs. Use these samples to check the code first. If the results do not match, modify the function and re-validate. This step gives the model basic debugging capabilities.

    A small number of samples only proves that the code passes those specific points; it does not guarantee correctness for all data. Spot-checking real data is still necessary before going live. Sample validation can be written as:

    1. samples = [({"Input": "2"}, 4.0), ({"Input": "x"}, None)]
    2. for row, expected in samples:
    3. got = solve_row(pd.Series(row))
    4. assert got == expected, f"Sample mismatch: input {row}, got {got}, expected {expected}"

    3. Identifying Structure and Batch Executing

    The difficulty with real tables lies in their non-fixed structure. Headers might be renamed, missing values and abnormal formats may appear, and the number of worksheets can change. A robust approach is to read the headers and the first few rows first, confirm column names and data types, and then iterate through all the data. When encountering rows that cannot be processed, they should be logged rather than interrupting the process or guessing a value to fill in.

    Capability Tiering: From Mechanical Execution to Autonomous Validation

    Based on their behavior, agents can be broadly divided into three tiers. This classification is based on behavioral effectiveness, not model size.

    Tier Typical Approach Main Risks Required Validation
    Mechanical Executor Generates answers one by one Error accumulation in long tasks, hard to reproduce results Manual verification per item
    Script Writer Writes scripts for fixed formats Fails when headers or formats change Re-test on new formats
    Autonomous Agent Writes general functions, designs test cases, checks environment Code logic flaws, data mishandling Sample checks plus real data spot-checks

    Mechanical executors may perform acceptably on small samples, but as tasks lengthen, errors easily compound. Script writers can handle loops but often hardcode column names or formats, requiring code changes whenever the input changes.

    Typical behaviors of autonomous agents include printing intermediate logs before execution, reading the first few rows to confirm column names and types, and writing handling logic for abnormal inputs. These behaviors make the code easier to inspect and less likely to fail silently under unexpected inputs.

    Three Key Risks Before Deployment

    1. Errors Escalate from Minor to Major Impact

    In a conversation, an incorrect answer is usually spotted by the reader at a glance. Code written by an agent directly manipulates files; an error could overwrite original data or write incorrect database records. Therefore, the execution pipeline needs two layers of protection: running in a sandbox and setting up manual approval for write, delete, and send operations.

    2. Costs Grow with Iterations

    Agents repeatedly go through the cycle of “write code, execute, read results, modify code.” Each turn consumes tokens, and tool calls may also incur fees. The total cost depends on task complexity, model choice, and the number of failures. It is recommended to test on a small sample first to estimate the cost for the full task.

    3. Permission Boundaries Must Be Specific to Paths and Operations

    If an agent runs under a user account, it theoretically has the same permissions as the user. During deployment, configure settings according to this checklist:

    • Grant read permissions only to directories required by the task, and write outputs to a separate directory.
    • Run in a container or virtual machine, prohibiting access to system directories and irrelevant networks.
    • Operations like delete, overwrite, and send must be manually confirmed.
    • Back up original files before each run to allow recovery in case of errors.
    • Output clear error messages and log them when errors occur, stopping subsequent steps without silent failures.

    Advice for Developers

    First, run on data copies instead of processing production data directly. Second, retain samples, run logs, and failure records for post-mortem review. Third, let the agent write the code while humans review the code and spot-check the results.

    The value of AI agents in batch processing tasks is undeniable, but their reliability depends on task definition, validation methods, and permission design. For teams, it is advisable to start with well-defined, reversible tasks before gradually expanding the scope.