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

# Code Execution

> Run Python and R code on a private compute server attached to your chat session.

Purna can write and execute Python and R code for analyses that go beyond built-in tools. When you request custom analysis, Purna provisions a **private compute server** for your chat session, writes code, runs it, and returns the results without requiring you to leave the conversation.

## Why use Code Execution?

Built-in tools handle common searches, summaries, and simple charts. Code Execution is for analyses that require custom logic, statistics, file processing, or figures that go beyond standard chart types.

| Capability                      | Built-in tools | Code Execution |
| ------------------------------- | -------------- | -------------- |
| Simple tables and summaries     | Yes            | Yes            |
| Bar, pie, and line charts       | Yes            | Yes            |
| Heatmaps and clustered plots    | No             | Yes            |
| Statistical tests and p-values  | No             | Yes            |
| Custom filtering logic          | Limited        | Yes            |
| Multi-step data transformations | Limited        | Yes            |
| Publication-quality figures     | Limited        | Yes            |
| R language support              | No             | Yes            |

## How it works

<Steps>
  <Step title="You ask for an analysis">
    Describe what you need in plain language. Reference any files with `@`. For example: *"Use @counts.tsv and @metadata.csv to run differential expression and create a volcano plot."*
  </Step>

  <Step title="Purna provisions a private server">
    A compute server is created and attached to your chat session. This server is private to you.
  </Step>

  <Step title="Relevant files are made available">
    Referenced uploads and generated files are copied into the server workspace so code can read them directly.
  </Step>

  <Step title="Code is written and executed">
    Purna writes Python or R code, executes it on the server, and streams results back into chat. Results can include text output, tables, charts, images, and downloadable files.
  </Step>

  <Step title="Server persists for follow-ups">
    The server stays attached to the chat session. Follow-up requests can reuse variables, intermediate results, and files from earlier executions.
  </Step>
</Steps>

<Note>
  The server automatically pauses when not in use and shuts down after inactivity. You are billed only for active server usage. See [Usage](/usage) for details.
</Note>

## Available libraries

Your compute server comes pre-loaded with a scientific computing environment.

### Python

| Category                  | Libraries                                             |
| ------------------------- | ----------------------------------------------------- |
| **Data science**          | pandas, NumPy                                         |
| **Visualization**         | matplotlib, seaborn, Plotly                           |
| **Statistics**            | SciPy, statsmodels, scikit-learn, pingouin            |
| **Bioinformatics**        | Biopython, pysam, cyvcf2, pybedtools, pyvcf3, pyfaidx |
| **Single-cell and omics** | scanpy and related analysis packages where available  |
| **Survival analysis**     | lifelines                                             |

### R

R is supported as an execution language with access to common statistical and bioinformatics packages.

### System tools

Common command-line tools such as samtools, bcftools, bedtools, and tabix are available for genomic and file-processing workflows.

## Working with files

Reference files with `@` in your prompt. Purna makes those files available in the compute workspace and writes code against the actual file paths.

Good prompts include:

* The file or files to use
* The columns or metadata that matter
* The comparison or transformation you want
* The desired output format
* Any statistical thresholds or plotting preferences

Example:

```
Use @counts.tsv and @metadata.csv. Compare treated vs control samples,
run differential expression, output a CSV of significant genes, and create
a volcano plot with adjusted p-value < 0.05 highlighted.
```

## Examples

### Heatmaps and clustered visualizations

Ask for heatmaps, clustered matrices, pathway score heatmaps, or feature-by-sample plots.

*Try: "Create a clustered heatmap of the top 50 variable genes in @expression\_matrix.tsv."*

### Advanced filtering and categorization

Use code when filtering requires multi-condition logic or custom scoring.

*Try: "Filter @screen\_results.csv for hits with effect size > 1.5, FDR \< 0.05, and replicate consistency above 0.8. Return a ranked table."*

### Statistical analysis

Run tests, models, confidence intervals, or enrichment calculations.

*Try: "Run a Fisher's exact test comparing pathway membership between the high-response and low-response groups in @annotations.csv."*

### Publication-quality figures

Generate multi-panel figures, violin plots, swarm plots, annotated scatter plots, and exportable PNG or SVG files.

*Try: "Create a violin plot of expression grouped by treatment condition, with significance annotations and a colorblind-safe palette."*

### Data transformation

Convert, clean, merge, or reshape files for downstream analysis.

*Try: "Merge @sample\_metadata.csv with @qc\_metrics.tsv by sample ID and export a cleaned table."*

## Billing

Code Execution uses a private compute server provisioned on demand.

* **Server time** is counted while the server is actively running code.
* **Paused servers** do not incur runtime charges.
* **Idle shutdown** frees resources after inactivity.

Usage details are available in account settings.

<Note>
  Each chat session gets its own server. Starting a new chat creates a new server. Returning to an existing chat can resume the same server state when available.
</Note>

## Tips for best results

<CardGroup cols={2}>
  <Card title="Reference files explicitly" icon="paperclip">
    Use `@filename` so Purna knows exactly which data to load.
  </Card>

  <Card title="Be specific about output" icon="bullseye">
    Tell Purna whether you want a table, plot, statistical result, script, or downloadable file.
  </Card>

  <Card title="Iterate in the same chat" icon="arrows-rotate">
    Follow-up requests can reuse the same server state. Ask Purna to adjust plots, rerun filters, or export additional formats.
  </Card>

  <Card title="Use jobs for long workflows" icon="gears">
    For multi-step pipelines or runs longer than a quick analysis, use [Jobs](/guides/jobs) instead.
  </Card>
</CardGroup>
