A lightweight CLI + web data analyst agent that can:
- Upload a local dataset (
.csv/.xlsx) into a secure, remote Python sandbox (E2B) - Let an LLM drive iterative analysis by executing Python code in the sandbox
- Save any static visualizations produced by the sandbox back to your machine under
charts/ - Provide a browser-based chat UI for the same agent workflow
This project showcases:
- Tool-using LLM orchestration
- Sandboxed code execution for safety
- Practical data-analysis UX via a simple terminal loop
agent.py runs a terminal application that:
- Creates a conversation/session using the OpenAI client
- Prompts you for a dataset path
- Creates an E2B sandbox
- Uploads your dataset into the sandbox
- Spins up an agent with a single tool:
python_code_execution - Runs an initial “understand the data” prompt
- Enters a chat loop where you can ask questions and the agent executes Python to answer
If the executed code generates display outputs (e.g., matplotlib with plt.show()), the tool:
- Extracts image artifacts from
execution.results - Saves them locally as:
charts/chart_<timestamp>_1.png
charts/chart_<timestamp>_2.png
...
If no chart artifacts are detected, the tool returns the available result formats to help debug.
Sandbox execution errors are written to:
error.log
This keeps your terminal output clean while preserving traceability.
app.py starts a Flask UI that:
- Accepts CSV/XLSX uploads and stores them in
uploads/ - Creates a sandbox session and uploads the file
- Returns an initial dataset summary
- Lets you chat with the agent through a minimal chat interface
- Cleans up the sandbox on session end
The web UI reuses the same agent logic, prompt, and chart-saving behavior as the CLI.
- Python (async)
- OpenAI SDK (
AsyncOpenAI) for model calls - E2B Code Interpreter (
AsyncSandbox) for sandboxed Python execution - Agents framework (
Agent,Runner,FunctionTool,ModelSettings) for tool-using orchestration - Flask for the web UI
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtNote: the
agentsdependency must match the library that provides:Agent,Runner,FunctionTool, andModelSettings. Ifpipcannot resolveagents, install the correct package for your environment.
You will need credentials for:
- OpenAI
- E2B
Typical setup (macOS / zsh):
export OPENAI_API_KEY="YOUR_OPENAI_KEY"
export E2B_API_KEY="YOUR_E2B_KEY"If your environment uses different variable names, set them according to your SDK configuration.
Run the app:
python agent.pyYou’ll be prompted:
- Dataset path (local):
Example:
Enter the path to the file you want to analyze: ./timeliner.xlsx
- Then interact with the agent:
Enter your message (or 'quit' to exit): summarize the dataset
Type quit to exit.
Run the web app:
python app.pyOpen the UI at:
http://localhost:5000
- Upload a CSV/XLSX file
- Wait for the initial analysis
- Ask follow-up questions in the chat input
- “Give me a 200 word summary of the dataset structure.”
- “List the columns and missingness rates.”
- “Compare mask usage across countries by income group.”
- “Which indicators differ the most between high- and low-income settings?”
- “Create a time series chart that shows the number of events recorded each month.”
- “Show monthly event counts by year and highlight spikes.”
Tip: for charts, ask explicitly for a visualization. The tool saves the image under
charts/.
charts/- Saved static plots (
.png/.svg) generated in the sandbox
- Saved static plots (
uploads/- Uploaded files for the web UI
error.log- Logged sandbox execution errors
- Async + CLI input: this is a simple terminal MVP and uses
input(). - File formats: the agent is instructed to load via
pd.read_csvorpd.read_exceldepending on the dataset. - Sandbox timeouts: the sandbox is currently created with
timeout=0(meaning depends on E2B defaults). Adjust as needed. - Chart generation: charts are saved only when the executed code produces a display result (e.g., with
plt.show()).
- Safety by design: code execution happens in an isolated sandbox, reducing risk.
- Tool-using agent loop: demonstrates how to wrap “code execution” as a tool for an LLM.
- Real developer ergonomics: persistent logs, deterministic chart saving, and a minimal but useful UX.
License: MIT