Data Analysis in the Workspace
Learn how to use runSQL, analyzeData, and the Python Sandbox for production data analysis.
Anakin Data Analysis Guide
The Anakin Workspace comes equipped with powerful, built-in tools for analyzing real production data. Agents in the workspace can execute queries, aggregate data, and even run advanced Python scripts on live databases via the Cloudflare Sandbox.
This guide details the core data analysis capabilities and how you can prompt your AI agents to use them.
1. Native Database Querying (runSQL)
Your agent can natively query the workspace's production D1 database using the runSQL tool.
How it Works
The agent can translate natural language questions into safe, read-only SELECT statements. The execution engine enforces strict security:
- No Destructive Commands: Any attempt to run DML/DDL commands (
UPDATE,DROP,INSERT) is intercepted and rejected by thevalidateSQLsecurity parser. - Robust Parsing: The parser is lexically aware, meaning it safely processes queries even if your target data contains semicolons (
;) or banned keywords inside strings (e.g.,WHERE status = 'CREATE').
Example Prompts
- "How many active leads are currently in the system?"
- "Show me the 5 most recent agent profiles that were created, ordered by creation date."
- "Which lead has the highest interest level, and what is their email?"
2. Advanced Data Summarization (analyzeData)
When you need statistical aggregation, you can rely on the analyzeData tool. It provides automated statistical summaries for your data.
How it Works
When the agent executes an analyzeData workflow, the system doesn't just return raw rows. For any numeric column in the result set, the engine automatically calculates:
- Minimum (
min) - Maximum (
max) - Average (
avg) - Sum (
sum) - Row Count (
count)
This saves tokens and processing time, giving the agent instant insights.
Example Prompts
- "Analyze the leads table and give me a breakdown of the interest levels. What is the average interest?"
- "Run a data analysis on agent activity. Give me the maximum and minimum engagement scores."
3. Python Sandbox Analysis (executeCode)
For highly complex data transformations or custom file processing, the AI agent can spin up its own secure Python container inside the Cloudflare Sandbox.
How it Works
1. Containerized Execution: The agent writes an analytical Python script and runs it in an isolated container.
2. Virtual Filesystem: The agent can use the writeSandboxFile tool to create .csv, .json, or .db (SQLite) files.
3. Seamless Syncing: Any database or file written by the agent inside the container is automatically synced to your R2 bucket and workspace dashboard without corruption, thanks to native binary array buffer syncing.
Example Prompts
- "Create a python script called analyze.py that connects to an SQLite database, creates a mock table of sales data, and prints out a summary."
- "Write a python script that reads the contents of my uploaded CSV file and calculates the standard deviation."
Security Guarantees
The Anakin platform is designed with a defense-in-depth security model:
- Zero-Trust SQL Validation:
runSQLandanalyzeDatastrip string literals out of the query before checking for banned keywords, ensuring malicious injections are caught without causing false positives. - Isolated Containers: Python code executed by the agent cannot access your production D1 database directly. It runs in a completely isolated network and filesystem.
- Owner Scope Enforcement: Powerful tools like SQL querying and Python execution are only exposed when the AI determines the current user is the Workspace Owner.
Harness the power of autonomous AI data analysis to extract insights from your platform in real-time!