What it does

The Execute Python tool runs Python code in a secure Jupyter notebook environment. Perfect for data analysis, calculations, visualizations, and any computational tasks your agents need to perform.

Key features

  • Execute Python code in isolated Jupyter notebook cells
  • Support for popular libraries (pandas, numpy, matplotlib, etc.)
  • Enhanced output display with separate sections for different output types
  • Smart output categorization - stdout, stderr, results, and text outputs are displayed distinctly
  • Automatic error handling with detailed tracebacks
  • Persistent session state across multiple executions

Parameters

ParameterTypeRequiredDescription
codestringYesThe Python code to execute in a single cell

Output types & display

The tool now intelligently categorizes and displays different types of output:

📤 Output (stdout)

Print statements and console output appear in a clean gray section:
print("Processing data...")
print("Results calculated successfully!")

📊 Result (expression results)

The final expression result is highlighted in a blue section:
# This result will be prominently displayed
42 + 8  # Shows: 50

⚠️ Warnings/Errors (stderr)

Non-fatal warnings and errors appear in an orange warning section:
import warnings
warnings.warn("This is a warning message")

🎨 Rich Media (charts, images, etc.)

Visual outputs like charts and images are displayed with full formatting:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [4, 5, 6])
plt.show()  # Chart appears as rich visual content

Common use cases

Data analysis with clear output

import pandas as pd
import numpy as np

# Create sample data
data = {'sales': [100, 150, 200, 175], 'month': ['Jan', 'Feb', 'Mar', 'Apr']}
df = pd.DataFrame(data)

print("Dataset created successfully!")  # Appears in Output section
print(f"Shape: {df.shape}")            # Appears in Output section

df.describe()  # Appears in Result section with rich formatting

Create visualizations with status updates

import matplotlib.pyplot as plt

print("Creating visualization...")  # Shows progress in Output

# Create a simple chart
plt.figure(figsize=(8, 6))
plt.plot([1, 2, 3, 4], [10, 20, 25, 30])
plt.title('Sample Chart')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')

print("Chart generated!")  # Confirms completion
plt.show()                 # Chart appears as rich visual

Mathematical calculations with explanations

import math

print("Calculating complex formula...")  # Process indicator

# Complex calculations
result = math.sqrt(144) + math.pow(2, 8)
print(f"Square root of 144: {math.sqrt(144)}")  # Step-by-step output
print(f"2 to the power of 8: {math.pow(2, 8)}")

result  # Final result prominently displayed

Error handling demonstration

import warnings

print("Starting calculation...")

# This generates a warning (appears in orange section)
warnings.warn("Using deprecated function")

# This works fine
result = 10 * 5
print(f"Calculation complete: {result}")

result  # Final result in blue section

Available libraries

Common Python libraries are pre-installed including:
  • Data Science: pandas, numpy, scipy, scikit-learn
  • Visualization: matplotlib, seaborn, plotly
  • Web: requests, beautifulsoup4
  • Utilities: json, csv, datetime, os, sys

Output formats

The tool supports rich output including:
  • Text: Standard print output and string representations
  • Images: PNG, JPEG, SVG graphics from matplotlib, plotly, etc.
  • HTML: Rich HTML content and tables
  • Charts: Interactive visualizations
  • Markdown: Formatted text with markdown syntax

Visual improvements

New in latest version:
  • Color-coded output sections for easy identification
  • Collapsible code view to focus on results
  • Success indicators for code that runs without visible output
  • Enhanced error display with structured error information
  • Rich media rendering for charts, images, and formatted data

Best practices

  • Use print() statements to show progress and intermediate results
  • Structure your code with clear steps and explanations
  • Handle errors gracefully with try/except blocks
  • Break complex operations into smaller, trackable steps
  • Import libraries at the beginning of your code

Troubleshooting

“Module not found” errors
  • Check if the library is in the available libraries list
  • Try importing alternative libraries with similar functionality
  • Use built-in Python modules when possible
“Code execution timeout”
  • Simplify complex operations
  • Avoid infinite loops or very long-running processes
  • Break large datasets into smaller chunks
“Memory errors”
  • Reduce dataset size or use sampling
  • Clear variables you no longer need with del variable
  • Use more memory-efficient data structures
“No output displayed”
  • Use print() statements to generate stdout output
  • Ensure your final line is an expression (not assignment) to see results
  • Check that your code doesn’t have syntax errors