Code Interpreter
A general-purpose code execution environment powered by AWS Bedrock AgentCore Code Interpreter. Run code, execute shell commands, and manage files in a secure sandbox.
Available Tools
- execute_code(code, language, output_filename): Execute Python, JavaScript, or TypeScript code.
- execute_command(command): Execute shell commands.
- file_operations(operation, paths, content): Read, write, list, or remove files in the sandbox.
- ci_push_to_workspace(paths): Save sandbox files to the shared workspace (S3). Omit
paths to save all files in the sandbox root.
Tool Parameters
execute_code
| Parameter |
Type |
Required |
Default |
Description |
code |
string |
Yes |
|
Code to execute. Use print() for text output. |
language |
string |
No |
"python" |
"python", "javascript", or "typescript" |
output_filename |
string |
No |
"" |
File to download after execution. Code must save a file with this exact name. Saved to workspace automatically. |
execute_command
| Parameter |
Type |
Required |
Description |
command |
string |
Yes |
Shell command to execute (e.g., "ls -la", "pip install requests"). |
file_operations
| Parameter |
Type |
Required |
Description |
operation |
string |
Yes |
"read", "write", "list", or "remove" |
paths |
list |
For read/list/remove |
File paths. read: ["file.txt"], list: ["."], remove: ["old.txt"] |
content |
list |
For write |
Entries with path and text: [{"path": "out.txt", "text": "hello"}] |
tool_input Examples
execute_code — text output
{
"code": "import pandas as pd\ndf = pd.DataFrame({'A': [1,2,3], 'B': [4,5,6]})\nprint(df.describe())",
"language": "python"
}
execute_code — generate chart
{
"code": "import matplotlib\nmatplotlib.use('Agg')\nimport matplotlib.pyplot as plt\nimport numpy as np\nx = np.linspace(0, 10, 100)\nplt.figure(figsize=(10,6))\nplt.plot(x, np.sin(x))\nplt.title('Sine Wave')\nplt.savefig('sine.png', dpi=300, bbox_inches='tight')\nprint('Done')",
"language": "python",
"output_filename": "sine.png"
}
execute_command — install a package
{
"command": "pip install yfinance"
}
execute_command — check environment
{
"command": "python --version && pip list | head -20"
}
file_operations — write a file
{
"operation": "write",
"content": [{"path": "config.json", "text": "{\"key\": \"value\"}"}]
}
file_operations — list files
{
"operation": "list",
"paths": ["."]
}
file_operations — read a file
{
"operation": "read",
"paths": ["output.csv"]
}
When to Use This Skill
Use code-interpreter as a sandbox for testing and prototyping code.
For production tasks (creating documents, charts, presentations), prefer specialized skills.
Do NOT use for:
- Formatting or displaying code examples (respond directly with markdown code blocks)
- Explaining code or algorithms (respond directly with text)
- Simple calculations you can do mentally (just provide the answer)
- Any task that doesn't require actual code execution
| Task |
Recommended Skill |
Notes |
| Create charts/diagrams |
visual-design |
Use this first for production charts |
| Create Word documents |
word-documents |
Has template support and styling |
| Create Excel spreadsheets |
excel-spreadsheets |
Has formatting pipeline and validation |
| Create PowerPoint |
powerpoint-presentations |
Has layout system and design patterns |
| Test code snippets |
code-interpreter |
Debug, verify logic, check output |
| Prototype algorithms |
code-interpreter |
Experiment before implementing |
| Install/test packages |
code-interpreter |
Check compatibility, test APIs |
| Debug code logic |
code-interpreter |
Isolate and test specific functions |
| Verify calculations |
code-interpreter |
Quick math or data checks |
Code Interpreter vs Code Agent
|
Code Interpreter |
Code Agent |
| Nature |
Sandboxed execution environment |
Autonomous agent (Claude Code) |
| Best for |
Quick scripts, data analysis, prototyping |
Multi-file projects, refactoring, test suites |
| File persistence |
Only when output_filename is set |
All files auto-synced to S3 |
| Session state |
Variables persist within session |
Files + conversation persist across sessions |
| Autonomy |
You write the code |
Agent plans, writes, runs, and iterates |
| Use when |
You need to run a specific piece of code |
You need an engineer to solve a problem end-to-end |
Workspace Integration
All files go to the code-interpreter/ namespace — a flat, session-isolated space separate from office documents.
Sandbox → Workspace (save outputs):
// Save a specific file after execution
{ "tool": "ci_push_to_workspace", "paths": ["chart.png", "results.json"] }
// Save everything in the sandbox root
{ "tool": "ci_push_to_workspace" }
// Alternative: save a single file inline during execute_code
{ "tool": "execute_code", "output_filename": "chart.png", "code": "..." }
Uploaded files (auto-preloaded):
Files uploaded by the user (e.g. ZIP archives) are automatically available in the sandbox — no manual loading needed. Just use them directly in execute_code.
Read saved files via workspace skill:
workspace_read("code-interpreter/chart.png")
workspace_read("code-interpreter/results.json")
workspace_list("code-interpreter/")
Text files (.py, .csv, .json, .txt, etc.) are transferred as-is.
Binary files (.png, .pdf, .xlsx, etc.) are handled via base64 encoding automatically.
Environment
- Languages: Python (recommended, 200+ libraries), JavaScript, TypeScript
- Shell: Full shell access via
execute_command
- File system: Persistent within session; use
file_operations to manage files
- Session state: Variables and files persist across multiple calls within the same session
- Network: Internet access available (can use
requests, urllib, curl)
Supported Languages
- Python (recommended) — 200+ pre-installed libraries covering data science, ML, visualization, file processing
- JavaScript — Node.js runtime, useful for JSON manipulation, async operations
- TypeScript — TypeScript runtime with type checking
Pre-installed Python Libraries
Data Analysis & Visualization
| Library |
Common Use |
pandas |
DataFrames, CSV/Excel I/O, groupby, pivot |
numpy |
Arrays, linear algebra, random, statistics |
matplotlib |
Line, bar, scatter, histogram, subplots |
plotly |
Interactive charts, 3D plots |
bokeh |
Interactive visualization |
scipy |
Optimization, interpolation, signal processing |
statsmodels |
Regression, time series, hypothesis tests |
sympy |
Algebra, calculus, equation solving |
Machine Learning & AI
| Library |
Common Use |
scikit-learn |
Classification, regression, clustering, pipelines |
torch / torchvision / torchaudio |
Deep learning, computer vision, audio |
xgboost |
High-performance gradient boosting |
spacy / nltk / textblob |
NLP, tokenization, NER, sentiment |
scikit-image |
Image processing, filters, segmentation |
Mathematical & Optimization
| Library |
Common Use |
cvxpy |
Convex optimization, portfolio optimization |
ortools |
Scheduling, routing, constraint programming |
pulp |
Linear programming |
z3-solver |
SAT solving, formal verification |
networkx / igraph |
Graph algorithms, network analysis |
File Processing & Documents
| Library |
Common Use |
openpyxl / xlrd / XlsxWriter |
Excel read/write with formatting |
python-docx |
Word document creation/modification |
python-pptx |
PowerPoint creation/modification |
PyPDF2 / pdfplumber / reportlab |
PDF read/write/generate |
lxml / beautifulsoup4 |
XML/HTML parsing |
markitdown |
Convert various formats to Markdown |
Image & Media
| Library |
Common Use |
pillow (PIL) |
Image resize, crop, filter, conversion |
opencv-python (cv2) |
Computer vision, feature detection |
imageio / moviepy |
Image/video I/O and editing |
pydub |
Audio manipulation |
svgwrite / Wand |
SVG creation, ImageMagick |
Data Storage & Formats
| Library |
Common Use |
duckdb |
SQL queries on DataFrames and files |
SQLAlchemy |
SQL ORM and database abstraction |
pyarrow |
Parquet and Arrow format processing |
orjson / ujson / PyYAML |
Fast JSON/YAML parsing |
Web & API
| Library |
Common Use |
requests / httpx |
HTTP requests, API calls |
beautifulsoup4 |
Web scraping |
fastapi / Flask / Django |
Web frameworks |
Utilities
| Library |
Common Use |
pydantic |
Data validation, schema definition |
Faker |
Test data generation |
rich |
Pretty printing, tables |
cryptography |
Encryption, hashing |
qrcode |
QR code generation |
boto3 |
AWS SDK |
For the full list of 200+ libraries with versions, run: execute_command(command="pip list")
Usage Patterns
Pattern 1: Data Analysis
import pandas as pd
import numpy as np
df = pd.DataFrame({
'date': pd.date_range('2024-01-01', periods=100),
'revenue': np.random.normal(1000, 200, 100),
'costs': np.random.normal(700, 150, 100),
})
df['profit'] = df['revenue'] - df['costs']
print("=== Summary Statistics ===")
print(df.describe())
print(f"\nTotal Profit: ${df['profit'].sum():,.2f}")
print(f"Profit Margin: {df['profit'].mean() / df['revenue'].mean() * 100:.1f}%")
Pattern 2: Visualization (with output_filename)
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import numpy as np
fig, axes = plt.subplots(2, 2, figsize=(14, 10))
categories = ['Q1', 'Q2', 'Q3', 'Q4']
values = [120, 150, 180, 210]
axes[0,0].bar(categories, values, color='#2196F3')
axes[0,0].set_title('Quarterly Revenue')
x = np.linspace(0, 10, 50)
axes[0,1].plot(x, np.sin(x), 'b-', linewidth=2)
axes[0,1].set_title('Trend')
sizes = [35, 30, 20, 15]
axes[1,0].pie(sizes, labels=['A','B','C','D'], autopct='%1.1f%%')
axes[1,0].set_title('Market Share')
x = np.random.normal(50, 10, 200)
y = x * 1.5 + np.random.normal(0, 15, 200)
axes[1,1].scatter(x, y, alpha=0.5, c='#FF5722')
axes[1,1].set_title('Correlation')
plt.tight_layout()
plt.savefig('dashboard.png', dpi=300, bbox_inches='tight')
print('Dashboard saved')
Pattern 3: Machine Learning
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report
from sklearn.datasets import load_iris
iris = load_iris()
X_train, X_test, y_train, y_test = train_test_split(
iris.data, iris.target, test_size=0.3, random_state=42
)
model = RandomForestClassifier(n_estimators=100, random_state=42)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
print(classification_report(y_test, y_pred, target_names=iris.target_names))
Pattern 4: SQL with DuckDB
import duckdb
import pandas as pd
orders = pd.DataFrame({
'order_id': range(1, 101),
'customer': [f'Customer_{i%20}' for i in range(100)],
'amount': [round(50 + i * 3.5, 2) for i in range(100)],
})
result = duckdb.sql("""
SELECT customer, COUNT(*) as cnt, ROUND(SUM(amount), 2) as total
FROM orders GROUP BY customer
HAVING COUNT(*) >= 3 ORDER BY total DESC LIMIT 10
""").df()
print(result.to_string(index=False))
Pattern 5: Fetch Data from Web
import requests
import pandas as pd
response = requests.get("https://api.example.com/data")
data = response.json()
df = pd.DataFrame(data)
print(df.head())
Pattern 6: Multi-step Workflow (session state persists)
Call 1: execute_code → load and clean data, store in variable `df`
Call 2: execute_code → analyze `df`, generate chart, save as PNG
Call 3: execute_code → export results to CSV
Call 4: file_operations(operation="read") → download the CSV
Variables (df) and files persist across calls in the same session.
Important Rules
matplotlib.use('Agg') before import matplotlib.pyplot — sandbox has no display.
- Use
print() for text output — stdout is how results are returned.
output_filename must match exactly — the filename in plt.savefig() or wb.save() must match the output_filename parameter.
- Use
execute_command for shell tasks — ls, pip install, curl, etc.
- Use
file_operations for file management — read/write/list/remove files explicitly.
- Session state persists — variables and files remain across calls. Use this for multi-step workflows.
Common Mistakes to Avoid
- Forgetting
matplotlib.use('Agg') before import matplotlib.pyplot as plt
- Using
plt.show() instead of plt.savefig() — there is no display
- Typo in
output_filename — must match the file saved by the code exactly
- Using
execute_code for shell tasks — use execute_command instead
- Writing binary files via
file_operations — use execute_code to generate binary files, then download with output_filename
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: code-interpreter3description: Test and prototype code in a sandboxed environment. Use for debugging, verifying logic, or installing packages. Use when this capability is needed.4---56# Code Interpreter78A general-purpose code execution environment powered by AWS Bedrock AgentCore Code Interpreter. Run code, execute shell commands, and manage files in a secure sandbox.910## Available Tools1112- **execute_code(code, language, output_filename)**: Execute Python, JavaScript, or TypeScript code.13- **execute_command(command)**: Execute shell commands.14- **file_operations(operation, paths, content)**: Read, write, list, or remove files in the sandbox.15- **ci_push_to_workspace(paths)**: Save sandbox files to the shared workspace (S3). Omit `paths` to save all files in the sandbox root.1617## Tool Parameters1819### execute_code2021| Parameter | Type | Required | Default | Description |22|-----------|------|----------|---------|-------------|23| `code` | string | Yes | | Code to execute. Use `print()` for text output. |24| `language` | string | No | `"python"` | `"python"`, `"javascript"`, or `"typescript"` |25| `output_filename` | string | No | `""` | File to download after execution. Code must save a file with this exact name. Saved to workspace automatically. |2627### execute_command2829| Parameter | Type | Required | Description |30|-----------|------|----------|-------------|31| `command` | string | Yes | Shell command to execute (e.g., `"ls -la"`, `"pip install requests"`). |3233### file_operations3435| Parameter | Type | Required | Description |36|-----------|------|----------|-------------|37| `operation` | string | Yes | `"read"`, `"write"`, `"list"`, or `"remove"` |38| `paths` | list | For read/list/remove | File paths. read: `["file.txt"]`, list: `["."]`, remove: `["old.txt"]` |39| `content` | list | For write | Entries with `path` and `text`: `[{"path": "out.txt", "text": "hello"}]` |4041## tool_input Examples4243### execute_code — text output4445```json46{47 "code": "import pandas as pd\ndf = pd.DataFrame({'A': [1,2,3], 'B': [4,5,6]})\nprint(df.describe())",48 "language": "python"49}50```5152### execute_code — generate chart5354```json55{56 "code": "import matplotlib\nmatplotlib.use('Agg')\nimport matplotlib.pyplot as plt\nimport numpy as np\nx = np.linspace(0, 10, 100)\nplt.figure(figsize=(10,6))\nplt.plot(x, np.sin(x))\nplt.title('Sine Wave')\nplt.savefig('sine.png', dpi=300, bbox_inches='tight')\nprint('Done')",57 "language": "python",58 "output_filename": "sine.png"59}60```6162### execute_command — install a package6364```json65{66 "command": "pip install yfinance"67}68```6970### execute_command — check environment7172```json73{74 "command": "python --version && pip list | head -20"75}76```7778### file_operations — write a file7980```json81{82 "operation": "write",83 "content": [{"path": "config.json", "text": "{\"key\": \"value\"}"}]84}85```8687### file_operations — list files8889```json90{91 "operation": "list",92 "paths": ["."]93}94```9596### file_operations — read a file9798```json99{100 "operation": "read",101 "paths": ["output.csv"]102}103```104105## When to Use This Skill106107Use code-interpreter as a **sandbox for testing and prototyping code**.108For production tasks (creating documents, charts, presentations), prefer specialized skills.109110**Do NOT use for:**111- Formatting or displaying code examples (respond directly with markdown code blocks)112- Explaining code or algorithms (respond directly with text)113- Simple calculations you can do mentally (just provide the answer)114- Any task that doesn't require actual code execution115116| Task | Recommended Skill | Notes |117|------|-------------------|-------|118| Create charts/diagrams | **visual-design** | Use this first for production charts |119| Create Word documents | **word-documents** | Has template support and styling |120| Create Excel spreadsheets | **excel-spreadsheets** | Has formatting pipeline and validation |121| Create PowerPoint | **powerpoint-presentations** | Has layout system and design patterns |122| **Test code snippets** | **code-interpreter** | Debug, verify logic, check output |123| **Prototype algorithms** | **code-interpreter** | Experiment before implementing |124| **Install/test packages** | **code-interpreter** | Check compatibility, test APIs |125| Debug code logic | code-interpreter | Isolate and test specific functions |126| Verify calculations | code-interpreter | Quick math or data checks |127128## Code Interpreter vs Code Agent129130| | Code Interpreter | Code Agent |131|---|---|---|132| **Nature** | Sandboxed execution environment | Autonomous agent (Claude Code) |133| **Best for** | Quick scripts, data analysis, prototyping | Multi-file projects, refactoring, test suites |134| **File persistence** | Only when `output_filename` is set | All files auto-synced to S3 |135| **Session state** | Variables persist within session | Files + conversation persist across sessions |136| **Autonomy** | You write the code | Agent plans, writes, runs, and iterates |137| **Use when** | You need to run a specific piece of code | You need an engineer to solve a problem end-to-end |138139## Workspace Integration140141All files go to the `code-interpreter/` namespace — a flat, session-isolated space separate from office documents.142143**Sandbox → Workspace (save outputs):**144145```json146// Save a specific file after execution147{ "tool": "ci_push_to_workspace", "paths": ["chart.png", "results.json"] }148149// Save everything in the sandbox root150{ "tool": "ci_push_to_workspace" }151152// Alternative: save a single file inline during execute_code153{ "tool": "execute_code", "output_filename": "chart.png", "code": "..." }154```155156**Uploaded files (auto-preloaded):**157158Files uploaded by the user (e.g. ZIP archives) are automatically available in the sandbox — no manual loading needed. Just use them directly in `execute_code`.159160**Read saved files via workspace skill:**161```162workspace_read("code-interpreter/chart.png")163workspace_read("code-interpreter/results.json")164workspace_list("code-interpreter/")165```166167> Text files (`.py`, `.csv`, `.json`, `.txt`, etc.) are transferred as-is.168> Binary files (`.png`, `.pdf`, `.xlsx`, etc.) are handled via base64 encoding automatically.169170## Environment171172- **Languages:** Python (recommended, 200+ libraries), JavaScript, TypeScript173- **Shell:** Full shell access via `execute_command`174- **File system:** Persistent within session; use `file_operations` to manage files175- **Session state:** Variables and files persist across multiple calls within the same session176- **Network:** Internet access available (can use `requests`, `urllib`, `curl`)177178## Supported Languages179180- **Python** (recommended) — 200+ pre-installed libraries covering data science, ML, visualization, file processing181- **JavaScript** — Node.js runtime, useful for JSON manipulation, async operations182- **TypeScript** — TypeScript runtime with type checking183184## Pre-installed Python Libraries185186### Data Analysis & Visualization187188| Library | Common Use |189|---------|------------|190| `pandas` | DataFrames, CSV/Excel I/O, groupby, pivot |191| `numpy` | Arrays, linear algebra, random, statistics |192| `matplotlib` | Line, bar, scatter, histogram, subplots |193| `plotly` | Interactive charts, 3D plots |194| `bokeh` | Interactive visualization |195| `scipy` | Optimization, interpolation, signal processing |196| `statsmodels` | Regression, time series, hypothesis tests |197| `sympy` | Algebra, calculus, equation solving |198199### Machine Learning & AI200201| Library | Common Use |202|---------|------------|203| `scikit-learn` | Classification, regression, clustering, pipelines |204| `torch` / `torchvision` / `torchaudio` | Deep learning, computer vision, audio |205| `xgboost` | High-performance gradient boosting |206| `spacy` / `nltk` / `textblob` | NLP, tokenization, NER, sentiment |207| `scikit-image` | Image processing, filters, segmentation |208209### Mathematical & Optimization210211| Library | Common Use |212|---------|------------|213| `cvxpy` | Convex optimization, portfolio optimization |214| `ortools` | Scheduling, routing, constraint programming |215| `pulp` | Linear programming |216| `z3-solver` | SAT solving, formal verification |217| `networkx` / `igraph` | Graph algorithms, network analysis |218219### File Processing & Documents220221| Library | Common Use |222|---------|------------|223| `openpyxl` / `xlrd` / `XlsxWriter` | Excel read/write with formatting |224| `python-docx` | Word document creation/modification |225| `python-pptx` | PowerPoint creation/modification |226| `PyPDF2` / `pdfplumber` / `reportlab` | PDF read/write/generate |227| `lxml` / `beautifulsoup4` | XML/HTML parsing |228| `markitdown` | Convert various formats to Markdown |229230### Image & Media231232| Library | Common Use |233|---------|------------|234| `pillow` (PIL) | Image resize, crop, filter, conversion |235| `opencv-python` (cv2) | Computer vision, feature detection |236| `imageio` / `moviepy` | Image/video I/O and editing |237| `pydub` | Audio manipulation |238| `svgwrite` / `Wand` | SVG creation, ImageMagick |239240### Data Storage & Formats241242| Library | Common Use |243|---------|------------|244| `duckdb` | SQL queries on DataFrames and files |245| `SQLAlchemy` | SQL ORM and database abstraction |246| `pyarrow` | Parquet and Arrow format processing |247| `orjson` / `ujson` / `PyYAML` | Fast JSON/YAML parsing |248249### Web & API250251| Library | Common Use |252|---------|------------|253| `requests` / `httpx` | HTTP requests, API calls |254| `beautifulsoup4` | Web scraping |255| `fastapi` / `Flask` / `Django` | Web frameworks |256257### Utilities258259| Library | Common Use |260|---------|------------|261| `pydantic` | Data validation, schema definition |262| `Faker` | Test data generation |263| `rich` | Pretty printing, tables |264| `cryptography` | Encryption, hashing |265| `qrcode` | QR code generation |266| `boto3` | AWS SDK |267268> For the full list of 200+ libraries with versions, run: `execute_command(command="pip list")`269270## Usage Patterns271272### Pattern 1: Data Analysis273274```python275import pandas as pd276import numpy as np277278df = pd.DataFrame({279 'date': pd.date_range('2024-01-01', periods=100),280 'revenue': np.random.normal(1000, 200, 100),281 'costs': np.random.normal(700, 150, 100),282})283df['profit'] = df['revenue'] - df['costs']284285print("=== Summary Statistics ===")286print(df.describe())287print(f"\nTotal Profit: ${df['profit'].sum():,.2f}")288print(f"Profit Margin: {df['profit'].mean() / df['revenue'].mean() * 100:.1f}%")289```290291### Pattern 2: Visualization (with output_filename)292293```python294import matplotlib295matplotlib.use('Agg')296import matplotlib.pyplot as plt297import numpy as np298299fig, axes = plt.subplots(2, 2, figsize=(14, 10))300301categories = ['Q1', 'Q2', 'Q3', 'Q4']302values = [120, 150, 180, 210]303axes[0,0].bar(categories, values, color='#2196F3')304axes[0,0].set_title('Quarterly Revenue')305306x = np.linspace(0, 10, 50)307axes[0,1].plot(x, np.sin(x), 'b-', linewidth=2)308axes[0,1].set_title('Trend')309310sizes = [35, 30, 20, 15]311axes[1,0].pie(sizes, labels=['A','B','C','D'], autopct='%1.1f%%')312axes[1,0].set_title('Market Share')313314x = np.random.normal(50, 10, 200)315y = x * 1.5 + np.random.normal(0, 15, 200)316axes[1,1].scatter(x, y, alpha=0.5, c='#FF5722')317axes[1,1].set_title('Correlation')318319plt.tight_layout()320plt.savefig('dashboard.png', dpi=300, bbox_inches='tight')321print('Dashboard saved')322```323324### Pattern 3: Machine Learning325326```python327from sklearn.model_selection import train_test_split328from sklearn.ensemble import RandomForestClassifier329from sklearn.metrics import classification_report330from sklearn.datasets import load_iris331332iris = load_iris()333X_train, X_test, y_train, y_test = train_test_split(334 iris.data, iris.target, test_size=0.3, random_state=42335)336337model = RandomForestClassifier(n_estimators=100, random_state=42)338model.fit(X_train, y_train)339y_pred = model.predict(X_test)340341print(classification_report(y_test, y_pred, target_names=iris.target_names))342```343344### Pattern 4: SQL with DuckDB345346```python347import duckdb348import pandas as pd349350orders = pd.DataFrame({351 'order_id': range(1, 101),352 'customer': [f'Customer_{i%20}' for i in range(100)],353 'amount': [round(50 + i * 3.5, 2) for i in range(100)],354})355356result = duckdb.sql("""357 SELECT customer, COUNT(*) as cnt, ROUND(SUM(amount), 2) as total358 FROM orders GROUP BY customer359 HAVING COUNT(*) >= 3 ORDER BY total DESC LIMIT 10360""").df()361print(result.to_string(index=False))362```363364### Pattern 5: Fetch Data from Web365366```python367import requests368import pandas as pd369370response = requests.get("https://api.example.com/data")371data = response.json()372df = pd.DataFrame(data)373print(df.head())374```375376### Pattern 6: Multi-step Workflow (session state persists)377378```379Call 1: execute_code → load and clean data, store in variable `df`380Call 2: execute_code → analyze `df`, generate chart, save as PNG381Call 3: execute_code → export results to CSV382Call 4: file_operations(operation="read") → download the CSV383```384385Variables (`df`) and files persist across calls in the same session.386387## Important Rules3883891. **`matplotlib.use('Agg')` before `import matplotlib.pyplot`** — sandbox has no display.3902. **Use `print()` for text output** — stdout is how results are returned.3913. **`output_filename` must match exactly** — the filename in `plt.savefig()` or `wb.save()` must match the `output_filename` parameter.3924. **Use `execute_command` for shell tasks** — `ls`, `pip install`, `curl`, etc.3935. **Use `file_operations` for file management** — read/write/list/remove files explicitly.3946. **Session state persists** — variables and files remain across calls. Use this for multi-step workflows.395396## Common Mistakes to Avoid397398- Forgetting `matplotlib.use('Agg')` before `import matplotlib.pyplot as plt`399- Using `plt.show()` instead of `plt.savefig()` — there is no display400- Typo in `output_filename` — must match the file saved by the code exactly401- Using `execute_code` for shell tasks — use `execute_command` instead402- Writing binary files via `file_operations` — use `execute_code` to generate binary files, then download with `output_filename`403404---405> Converted and distributed by [TomeVault](https://tomevault.io/claim/aws-samples) — claim your Tome and manage your conversions.406<!-- tomevault:4.0:skill_md:2026-04-11 -->