← Back to Blog
Header image for blog post: How to build and run an AI data analysis agent
Daniel Adeboye
Published 11th September 2026

How to build and run an AI data analysis agent

TL;DR: how to build and run an AI data analysis agent

  • An AI data analysis agent combines a language model with tools for querying databases, executing Python, accessing files, and working with the data sources required for analysis.
  • The agent can autonomously choose which tools to use, execute them in sequence, interpret the results, and produce an answer, visualization, or report.
  • Production data analysis agents need sandboxed execution because they run AI-generated SQL and Python against real data. A misconfigured agent or prompt injection can otherwise lead to unintended queries, data access, or resource usage.
  • Northflank provides the infrastructure for running these agents, with GPU workloads for hosting models, services for the agent, isolated sandboxes for generated code, managed databases and storage for data, and networking, secrets, and enterprise governance controls.
  • Run the entire stack on Northflank's managed cloud or in your own cloud through BYOC.

Build and run your AI data analysis agent on Northflank. Get started with Northflank (self-serve), or book a demo to explore the right setup for your workloads and infrastructure.

Data analysis agents do not wait to be asked a question. They connect to your databases, run queries, execute Python against the results, interpret what they find, and produce reports autonomously. Point one at your PostgreSQL database and ask it to identify revenue trends by region for the last quarter. It writes the SQL, runs it, processes the output, and returns a structured analysis. No dashboard. No SQL engineer. No waiting.

Building an agent against a sample dataset is straightforward. Running one in production against real customer data, with real database credentials and autonomous code execution, is a different problem. The agent needs sandboxed execution so a misconfigured query or manipulated prompt cannot access more than it should. Database credentials need to be managed centrally and injected at runtime, while teams with data residency or network requirements may need to run the agent inside their own cloud infrastructure. This article covers both sides: building the agent and running it safely in production.

What an AI data analysis agent actually does

An AI data analysis agent is more than a chatbot with database access. It can plan a data analysis, choose the tools it needs, execute queries or code, interpret the results, and produce a final answer without requiring a human to handle each step.

The core capabilities are:

  1. Natural language to SQL or Python: The agent interprets a question in plain English and translates it into the queries or code needed to answer it. For example, “Which product categories drove the most revenue growth last quarter?” might require the agent to identify the relevant tables, filter the correct dates, calculate growth, and aggregate the results.
  2. Tool calling and execution: The agent does not just generate SQL or Python. It calls tools that execute them. A SQL tool can query a database, a Python tool can perform data manipulation or statistical analysis, and a file tool can read datasets or write reports. The agent decides which tools to use based on the task and the results it receives.
  3. Result interpretation and synthesis: The agent inspects the output from its tools, identifies relevant findings, and determines whether additional analysis is needed. It can then combine the results into an explanation rather than simply returning raw query output.
  4. Report generation: The final output can be a written analysis, table, chart, or report with the findings and recommendations relevant to the original question.

Why production data analysis agents need sandboxed execution

Running an AI data analysis agent against real production data introduces risks that do not exist in a local prototype.

  • AI-generated code runs with real permissions: The agent writes and executes SQL and Python autonomously, and that code has access to whatever the underlying connections permit. A destructive query generated because of a hallucination, bug, or prompt injection can execute with the same permissions as a legitimate query. Sandboxed execution provides a separate boundary for generated code and helps contain its effects.
  • Prompt injection via data: A data analysis agent can process user-generated or otherwise untrusted data. A malicious value in a user_comments column, for example, could contain instructions designed to influence the agent, such as accessing unrelated data or sending information to an external endpoint. The execution environment should constrain what the agent can access even when the data it reads is adversarial.
  • Database credentials are high-value targets: An agent that connects to a production database may have access to sensitive data and operations. Database credentials should therefore be managed centrally, scoped to the task, and injected at runtime rather than hard-coded into the application or execution image.
  • Multi-tenant isolation: When multiple users or teams run data analysis agents, each execution environment should be isolated from the others. One agent should not be able to access another user's files, query results, credentials, or running processes.
  • Data residency: Some organizations need data processing to remain within a specific cloud account, region, or network boundary because of regulatory or contractual requirements. In those cases, the agent and its execution environment may need to run inside the organization's own infrastructure rather than on shared external infrastructure.

How to build and sandbox an AI data analysis agent on Northflank

The architecture of an AI data analysis agent has three layers: the model that reasons and plans, the tools it calls to interact with data, and the execution environment where those tool calls run.

image.png

The model layer handles reasoning and planning. Given an input, it decides which tools to call, what arguments to pass, and how to interpret the results. Tool calling APIs from model providers let the model return structured tool calls that the agent runtime executes. You can also run models on Northflank's GPU infrastructure when you need to host your own models.

The tool layer defines what the agent can do. A SQL query tool can execute a query and return rows, a Python execution tool can run analysis code, and a file tool can read datasets or write output files. Each tool connects to the resources required by the analysis and returns the results to the agent.

The execution layer is where those tool calls actually run. For a production data analysis agent, this means:

  • SQL queries run against a database using credentials scoped to the agent's workload rather than hardcoded credentials.
  • Python and other generated code run inside an isolated sandbox so the execution environment is separated from the agent service and underlying host.
  • File operations are restricted to the workspace and storage the agent is explicitly given, with ephemeral or persistent storage depending on the workflow.

On Northflank, the execution layer can use microVM-isolated Sandboxes for Python and other generated code, alongside managed databases for structured data. Database credentials can be stored in secret groups and provided to workloads at runtime. The agent itself can run as a Northflank service, with sandbox environments created programmatically when additional code execution is required.

For the full SDK reference on creating and managing sandbox environments, see the Northflank Sandboxes documentation.

Build and run your AI data analysis agent on Northflank. Get started with Northflank (self-serve), or book a demo to explore the right setup for your workloads and infrastructure.

How Northflank handles AI data analysis infrastructure

Running a data analysis agent in production means operating more than the model. Someone has to provide the database the agent queries, isolate generated code execution, manage credentials, store analysis outputs, and support the infrastructure as workloads grow.

Northflank provides the infrastructure and execution layer around the agent, from the environment where you build and run the agent to the isolated environments where generated code executes.

  • MicroVM sandbox isolation: Run AI-generated Python and other untrusted code inside microVM-backed Sandboxes with VM-level isolation. Sandboxes boot in under 1 second and can be created and managed programmatically.
  • Harnesses: Use cloud coding environments to build, test, and run AI-powered workflows with dedicated compute, storage, networking, and runtime configuration. Harnesses can be used alongside Sandboxes when your data analysis workflow also includes an AI coding agent or interactive development environment.
  • Managed databases and storage: Run PostgreSQL, MySQL, MongoDB, Redis, and MinIO alongside your agent workloads. Database connection details can be provided to services and jobs through runtime variables or secret groups.
  • Secrets management: Store database credentials, API keys, and other sensitive values in secret groups and provide them to workloads at runtime. Secrets can be restricted to specific services or jobs.
  • Managed cloud or BYOC: Run the agent, sandbox execution, and supporting infrastructure on Northflank's managed cloud or in your own cloud environment through BYOC.
  • Network controls: Control how agent workloads communicate with databases, APIs, and other services using Northflank's networking and policy controls.
  • Enterprise governance: Control who can deploy and manage agent workloads with role-based access control and enterprise SSO through SAML and OIDC. Audit logs provide visibility into infrastructure and configuration changes for investigating unexpected behavior.
  • Services, jobs, and storage: Run the agent API as a service, move long-running analysis into jobs, and use persistent storage when datasets or generated artifacts need to survive beyond a single execution.
  • GPU workloads: Run GPU-backed workloads when the analysis workflow also requires local model inference, vision models, or other GPU-accelerated processing.

The point is not to replace the agent framework or dictate which model you use. You build the reasoning and tool-calling layer while Northflank provides the environment those tools run against, from sandboxed code execution and databases to storage, networking, and infrastructure.

Build the agent logic. Let Northflank handle the infrastructure it runs on.

Conclusion

Building an AI data analysis agent is only part of the problem. Once the agent works with real data and executes SQL or Python autonomously, production introduces new challenges around sandboxed execution, credential management, data access, and infrastructure.

Northflank provides the infrastructure layer those agents need: managed databases for data, microVM-isolated Sandboxes for generated code execution, secrets management for credentials, networking and governance controls, and BYOC for teams that need to run workloads in their own cloud infrastructure.

FAQ: how to build and run an AI data analysis agent

What is an AI data analysis agent?

An AI data analysis agent connects to data sources, generates and executes queries or code, interprets the results, and produces structured analysis without requiring a human to handle each step. Unlike a BI dashboard with predefined metrics or a chatbot that answers a single question, an agent can plan and execute a multi-step analysis using tools for database access, code execution, and file management.

What tools does a data analysis agent need?

At minimum, a data analysis agent needs a SQL query tool and a Python execution tool. Production agents may also need file tools for reading datasets and generating reports, as well as API tools for pulling data from external sources. The model chooses which tools to call as it works through the analysis.

Why does a data analysis agent need a sandbox?

Data analysis agents execute AI-generated SQL and Python against real data and infrastructure. A hallucinated query, misconfiguration, or prompt injection can cause unintended data access, expensive queries, or destructive actions. A sandbox isolates generated code from the host and other workloads while limiting the resources and services it can access.

Can a data analysis agent run inside my own cloud account?

Yes. Northflank BYOC lets you run the agent and its supporting workloads in your own cloud infrastructure, including AWS, GCP, Azure, Oracle, and CoreWeave. This is useful when data or workloads need to remain within your organization's cloud environment and network.

How do you secure database credentials for a data analysis agent?

Store database credentials in a secrets manager and provide them to the agent at runtime rather than hardcoding them in source code or configuration files. On Northflank, secret groups can provide credentials to the workloads that need them while keeping them separate from the generated code execution environment.

Share this article with your network
X