Skip to main content
Use Gravix Layer 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.

Overview

A typical workflow looks like this:
  1. You (or your app) ask the model to analyze a dataset with natural-language prompts.
  2. The model returns Python inside a fenced code block.
  3. Gravix Layer runs that code inside a dedicated Runtime (not your laptop).
  4. Stdout/stderr go back into the chat so the model can fix or extend the code across several rounds.
  5. Charts are written under /workspace/charts in the runtime and can be downloaded to your project folder.
Nothing in the user’s prompt runs locally except the small driver script that calls the API.

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.
Full source: gravixlayer-python/examples/agents/python/data-analyst-agent.

How it works

The script uses the high-level 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 (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:
Or copy only this directory from the monorepo if you already have it checked out.

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:
Optional: copy .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

From examples/agents/python/data-analyst-agent:
The script will:
  1. Create an Runtime (template defaults to base-medium unless you set GRAVIXLAYER_TEMPLATE).
  2. Download the CSV and install analysis packages in the runtime.
  3. Loop over analysis steps: LLM → code → run_code → feed output back until the step completes (up to five LLM rounds per step).
  4. Download generated charts into a local ./charts folder.

5. Dataset and outputs

6. Configuration reference

7. Core pattern (simplified)

The example wraps execution like this (conceptually):
The LLM is prompted so each code block re-imports libraries and reloads the CSV (execution cells are isolated unless you use a persistent code context).

Next steps

  • Read the README in the repo for the step-by-step analysis table and project layout.
  • Explore Runtime and run Python in the docs.
  • Swap prompts or datasets by editing ANALYSIS_STEPS and DATASET_URL in data_analyst_agent.py.