Understanding and Building an AI Agent news update
Developer Vinitha V N designed an autonomous data agent that runs Python in an isolated container and uses an eight-turn loop to correct messy sales data.
By Dillip Chowdary • Nov 29, 2026 • Source: vinithavn.substack.com

At a glance
- Product
- Data Analysis Agent
- Author
- Vinitha V N
- Publication date
- Nov 29, 2026
- Execution timeout
- 30 seconds
- Maximum turns
- 8 turns
- Primary tools
- inspect_dataset, execute_python, final_answer
In this post
Software developer Vinitha V N detailed the architecture for an autonomous Data Analysis Agent designed to answer natural-language spreadsheet questions by iteratively writing and executing Python scripts, according to vinithavn.substack.com's report. The project examines how structured software controls convert a standard large language model into an iterative system capable of parsing tabular data, recovering from runtime crashes, and resolving logical discrepancies.
This analysis breaks down the transition from a rigid four-stage code generation pipeline into a dynamic multi-turn agent loop backed by sandboxed execution environments. It is written for software engineers, data practitioners, and systems architects who are developing automated analytical tools and need practical patterns for managing context windows, error handling, and runtime execution boundaries.
01Linear script pipeline and execution flaws
The initial foundation relies on a deterministic four-stage procedure that attempts to answer user queries through a single model pass. This straightforward design connects the user prompt to an automated Python runner without intermediate human intervention.
- Context assembly The application extracts column titles and data types from the target spreadsheet and pairs them with the incoming query.
- Code generation The language model receives the prompt, drafts the required Python code, and writes the contents to an executable script.
- Automated execution The host environment executes the generated file automatically and captures the terminal output for evaluation.
- Result explanation The model reviews the terminal output and generates a natural-language summary that explains the findings to the user.
While this linear process answers basic questions like identifying the product category with the highest profit, it fails whenever execution anomalies arise. A simple casing discrepancy such as requesting a lowercase profit column when the table uses title case triggers an unhandled KeyError. Furthermore, scripts risk entering infinite execution loops, overwhelming users by dumping thousands of raw spreadsheet rows, or inadvertently overwriting pristine source files on disk.
02Container sandboxes and thirty-second execution boundaries
To mitigate these operational vulnerabilities, the architecture introduces rigorous execution limits alongside selective context pruning. Passing an entire dataset directly within the prompt quickly exhausts model token budgets and consumes large segments of the context window. The system instead extracts schema metadata, column types, and representative sample rows, allowing the script to reference the full file locally as an isolated variable without bloating the prompt payload.
The runtime layer isolates script execution within an ephemeral sandbox container provisioned without network access and running under unprivileged user permissions. The application checks for Docker availability by default, falling back to a plain host subprocess if the container daemon is unavailable. Once script execution concludes, the platform purges the container entirely to eliminate persistent side effects across tasks.
Execution limits prevent runaway routines and oversized console outputs from degrading performance. A strict 30-second timeout halts hanging processes and records an explicit timeout notification for review.
When a routine outputs excessive text, such as an entire dataset, the executor trims the console stream to retain only the opening and trailing lines. The system also captures raw tracebacks during syntax or key crashes, passing them back to the model for clarification.
03Dynamic state evaluation across autonomous workflows
Advertisement
Tech Pulse Daily
Get tomorrow's pulse first
Join engineers who read Tech Pulse before stand-up. Free, weekday mornings.
The core distinction between a baseline script runner and a true agent centers on dynamic autonomy. In the baseline system, a predetermined host script controls each step in an immutable sequence, using the model merely as an isolated text generator. An agentic workflow shifts control directly to the model, allowing it to evaluate its current operational state and choose its next action dynamically.
| Execution Property | Baseline Script Pipeline | Dynamic Agent Loop |
|---|---|---|
| Control Flow | Hardcoded procedural script | Model decides next step |
| Error Handling | Program crashes on exceptions | Autonomous self-correction |
| Data Inspection | Single static schema pass | Dynamic row inspection |
| Output Validation | Assumes code logic is correct | Iterative output review |
This dynamic shift enables systems to handle subtle logical flaws that do not produce standard compiler or interpreter errors. For instance, when a sales column contains fragmented entries such as title-cased North and lowercase north, standard scripts treat them as separate regional entities without warning. An autonomous agent inspects intermediate outputs, discovers inconsistent groupings, and adjusts its subsequent code without requiring human debugging.
04Three core tools and eight-turn limits
To grant the model autonomous operational authority, the host system exposes three specialized functions defined by detailed descriptions and explicit input parameters. The inspect_dataset function provides on-demand dataset summaries and extra sample rows when schema context proves insufficient.
The execute_python tool takes generated code strings and executes them inside the sandbox environment, returning output logs or errors. The final_answer function concludes the run with verified metrics and documented assumptions.
During each cycle of the agent loop, the system sends the full conversational history to the model, including previous tool invocations and execution outputs. If the model responds without a tool invocation, the platform re-prompts it to pick an action or finalize the response. The agent evaluates function descriptions against its current task status, selecting tools sequentially until completing its analysis.
Note: The runtime platform enforces a hard limit of 8 turns to prevent infinite execution loops while preserving full interaction context on every cycle.
05Multi-turn self-correction on inconsistent sales categories
The power of dynamic tool usage appears when calculating regional sales metrics across messy records. In a test run querying total sales by region, the agent invoked the dataset inspection tool in its initial turn to verify table structures. On turn two, it drafted an aggregation script using the code execution tool, which revealed seven distinct geographic groups caused by inconsistent capitalization across regional labels.
Rather than returning this skewed output, the agent recognized the category fragmentation on turn three. It authored a revised Python routine that stripped superfluous whitespace and normalized regional strings into lowercase values. A subsequent execution confirmed that regional classifications consolidated cleanly into four distinct groups.
On turn five, the agent called the final answer tool with accurate sales totals for the four corrected territories alongside documentation of its data cleaning steps. Because the agent reviewed its own execution artifacts against reality, it corrected the underlying data defect without human prompts or external error triggers.
Frequently asked questions
What tools are available to the Data Analysis Agent?
The agent has access to inspect_dataset for examining schemas and rows, execute_python for running scripts in a sandbox, and final_answer for delivering results and documenting assumptions.
How does the system secure code execution?
Code runs inside an unprivileged Docker container with no network access that is deleted after execution, falling back to a local subprocess if Docker is unavailable.
How does the agent handle unexpected data formatting issues?
The agent reviews the outputs returned by its execution tool, identifies logical inconsistencies such as duplicate category names caused by mixed casing, and executes cleanup scripts to normalize data before delivering the final answer.
What limits prevent the agent from hanging or looping endlessly?
The executor terminates scripts that run past 30 seconds and restricts the overall agent conversation to a hard ceiling of 8 turns.
Sources
Author
Dillip Chowdary
Writes Tech Bytes coverage of AI, engineering, and the tools that actually ship. Editor of Tech Pulse Daily.
Related on Tech Bytes
Advertisement