Use Gravix Layer Agent Runtimes to run AI-generated Python safely in an isolated microVM. This guide walks through the official Data Analyst Agent example: an OpenAI-compatible LLM writes analysis code, the runtime executes it, and you get text insights plus PNG charts on disk.Documentation Index
Fetch the complete documentation index at: https://docs.gravixlayer.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
A typical workflow looks like this:- You (or your app) ask the model to analyze a dataset with natural-language prompts.
- The model returns Python inside a fenced code block.
- Gravix Layer runs that code inside a dedicated Agent Runtime (not your laptop).
- Stdout/stderr go back into the chat so the model can fix or extend the code across several rounds.
- Charts are written under
/workspace/chartsin the runtime and can be downloaded to your project folder.
What you’ll build
- Loads the Seaborn Diamonds dataset (≈54k rows) from a public URL inside the runtime.
- Installs pandas, matplotlib, seaborn, etc. inside the runtime via
pip. - Runs five analysis steps (overview, plots, cross-tabs, written summary).
- Saves PNG charts and optionally prints an execution timing summary.
How it works
Runtime helper from gravixlayer.types.runtime: it creates a runtime, runs runtime.run_code(...) in a loop, then downloads PNGs with the SDK file APIs.
Prerequisites
- Python 3.9+
- Gravix Layer API key (Agent Runtime access)
- An OpenAI-compatible API key (OpenAI, or any provider with a compatible base URL—Groq, Together, OpenRouter, etc.)
1. Get the example
Clone the repo and enter the example folder:2. Install dependencies
Create a virtual environment and install requirements:requirements.txt pins:
3. Configure API keys
Get a Gravix Layer key from gravixlayer.ai and export both keys in your shell:.env.example to .env if you use python-dotenv in your own wrapper; the stock script reads the environment directly.
Optional: other LLM providers
Point the OpenAI client at a compatible base URL and model, for example:4. Run the agent
Fromexamples/agents/python/data-analyst-agent:
- Create an Agent Runtime (template defaults to
python-3.14-base-mediumunless you setGRAVIXLAYER_TEMPLATE). - Download the CSV and install analysis packages in the runtime.
- Loop over analysis steps: LLM → code →
run_code→ feed output back until the step completes (up to five LLM rounds per step). - Download generated charts into a local
./chartsfolder.
5. Dataset and outputs
| Item | Detail |
|---|---|
| Dataset | Seaborn diamonds — price, carat, cut, color, clarity, etc. |
| Remote path | /workspace/diamonds.csv |
| Charts | e.g. price_by_cut.png, carat_vs_price.png, price_by_color_clarity.png under /workspace/charts |
6. Configuration reference
| Variable | Required | Default | Description |
|---|---|---|---|
OPENAI_API_KEY | Yes | — | Provider API key |
GRAVIXLAYER_API_KEY | Yes | — | Gravix Layer key |
OPENAI_API_BASE_URL | No | https://api.openai.com/v1 | Compatible API base |
OPENAI_MODEL | No | gpt-4o | Model name |
GRAVIXLAYER_TEMPLATE | No | python-3.14-base-medium | Runtime template |
GRAVIXLAYER_TIMEOUT | No | 600 | Runtime timeout (seconds) |
7. Core pattern (simplified)
The example wraps execution like this (conceptually):Next steps
- Read the README in the repo for the step-by-step analysis table and project layout.
- Explore Agent Runtime and run Python in the docs.
- Swap prompts or datasets by editing
ANALYSIS_STEPSandDATASET_URLindata_analyst_agent.py.