---
title: "Python Analysis"
description: "How Datarelix runs Python: when a sandbox step is planned, which libraries are available, and the limits it enforces."
canonical: https://docs.datarelix.ai/guides/python/
---

# Python Analysis

Some questions can't be answered with SQL alone — distributions, regressions, custom transforms. Datarelix runs Python in an isolated sandbox to handle them.

## When Python runs

- When a question needs analysis beyond SQL — typically charts or aggregations that pandas does better than SQL.
- When you toggle the chart icon and the plan includes a sandbox step.

Sandbox steps consume the SQL step's results. The DataFrame you get is the rows the SQL step produced.

## What's available in the sandbox

- **pandas, numpy** for data manipulation.
- **scipy, statsmodels** for stats.

The sandbox runs a fixed, vetted set of scientific-Python libraries — pandas, numpy, scipy, and statsmodels. Arbitrary package installs are not available.

Charts are **not** authored in Python. When your question warrants a visualization,
Datarelix generates a declarative chart spec from the query result and renders it as an
interactive Vega-Lite chart — the sandbox is for data analysis (transforms, stats), not plotting.

## What's NOT available

- **No network.** The sandbox cannot make outbound HTTP calls. You can't `requests.get("...")` to leak data.
- **No filesystem outside the run scratch dir.** No reading from your home dir, no writing to `/tmp` indefinitely.
- **No shell.** `os.system` and `subprocess` are blocked.
- **No native code loading.** No `ctypes`, no FFI.

These boundaries are enforced at the OS level (read-only root filesystem, dropped capabilities, network namespace isolation).

## Resource limits

| Limit | Default |
|-------|---------|
| Wall-clock timeout | 30s |
| Memory | 512 MB |
| CPU | 1 core |
| Output bytes | 10 MB |

These limits keep analysis fast and bounded. Enterprise plans can raise them — [contact us](https://datarelix.ai/contact/).

## Inspecting a sandbox step

Open the trace toggle on the assistant message. You'll see:

- The Python source the LLM produced.
- The DataFrame it consumed (referenced by name).
- The artifact it produced (table or chart).
- Stdout / stderr captured during execution.

If something failed, the error class will be `CODE_ERROR` and the exception type/message is in the trace.

## When Python isn't the answer

If the generated Python repeatedly fails or doesn't match the question, Datarelix retries up to the configured repair budget (default: 3). After that the run is marked failed with a `PLAN_FAILURE`. Edit the question and ask again.
