> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bigdata.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Code execution and charts

> How the Research Agent and Workflows run Python to analyze structured data and produce charts, and how to configure and read them.

The agent can write and run Python in a secure sandbox. It uses this to work with
structured data. It can pull financials, prices, and holdings as tables, then filter,
aggregate, and compute over them. This answers quantitative questions that search
alone cannot. When you turn charting on, the same step can turn the results into a
chart. The agent sends each chart back as a
[`CHART`](/how-to-guides/agents/concepts/streaming-responses#chart) message.

This works on both the Research Agent (`/v1/research-agent`) and Workflows
(`/v1/workflow/execute`).

## Security

Each request runs in its own sandbox on a fresh process. No state is kept between
requests. The code the model writes never sees your credentials. It cannot reach
arbitrary external services. It can only read Bigdata's own governed data APIs.

## Usage

Code execution can run several analysis steps in one request. It can therefore use
more content than a plain query. We monitor and optimize this with internal
evaluations to keep it efficient. You can turn the tool off per request if you
prefer.

## Configuration

Configure code execution under the `python_code_execution` key of `tools_configs`:

```json theme={null}
{
  "tools_configs": {
    "python_code_execution": {
      "enabled": true,
      "chart_generation_enabled": true
    }
  }
}
```

* `enabled` sets whether the agent may run Python. Set it to `false` to turn code
  execution off for a request.
* `chart_generation_enabled` sets whether the agent may produce charts. Charts are
  off by default. Leave this `false` if you only want computed results in the answer
  text and no `CHART` messages.

For Workflows, you can store the same `python_code_execution` config on a template's
`tools_configs`. Every run of that template then uses it.

## Charts

When `chart_generation_enabled` is `true` and the agent decides a chart helps, it
sends a [`CHART`](/how-to-guides/agents/concepts/streaming-responses#chart) message.
Each `CHART` message includes a `vega_lite_spec`. This is a standard
[Vega-Lite](https://vega.github.io/vega-lite/docs/) specification. You can render it
with any Vega-Lite renderer. Each message also includes `start` and `end` offsets.
These point to a span of the answer text, so you can place the chart where the answer
refers to it. This is the same offset model used by
[grounding citations](/how-to-guides/agents/concepts/grounding-and-citations).

### Example

Take a request such as "Chart Tesla's total quarterly revenue for the last six
reported quarters." The agent pulls the figures from Bigdata's financials data,
computes the series, and returns a `CHART` message. Rendering its `vega_lite_spec`
produces this chart:

<Frame>
  <img src="https://mintcdn.com/ravenpackinternational/0UwE9CIcFv7xVbyh/images/agents/tesla-quarterly-revenue.png?fit=max&auto=format&n=0UwE9CIcFv7xVbyh&q=85&s=a11f8176b043e819b980ed0a6110d322" alt="Bar chart of Tesla quarterly revenue" width="1288" height="986" data-path="images/agents/tesla-quarterly-revenue.png" />
</Frame>

The chart is rendered from the `vega_lite_spec` in the `CHART` message.
