1. What is this, Really?
The Python Playground is a full Python 3 interpreter running inside your browser tab via WebAssembly (Pyodide). Code never leaves your device and requires no backend server.
Pyodide downloads the initial runtime (~6-10MB) on first launch. You can process algorithms, analyze CSV data with Pandas, compute matrix algebra with NumPy, and render Matplotlib charts directly in-browser.
2. Opening the Python Playground
Launch via Sidebar → Experimental → Python Sandbox. Features a project selector, code editor, stdout terminal console, and dedicated PNG plot preview pane.
When AI agents emit <python_tool> blocks, code executes silently in a background web worker and streams stdout into thinking traces.
3. Running Your First Script
Write standard Python code in the editor and click Run Python Code. The console displays web worker initialization logs, auto-installed packages, formatted stdout output, and detailed tracebacks for syntax errors.
4. Supported Packages & WASM Capabilities
numpy(matrix algebra & math)pandas(DataFrames & CSV parsing)matplotlib(charts & visual plots)micropip(in-browser package installer)
- No direct local file system access (paste CSVs as strings)
- No arbitrary HTTP networking inside WASM
- GUI windows like Tkinter or Pygame windows are shimmed
5. Plotting — Matplotlib Visual Outputs
When your code invokes plt.show(), Pyodide captures the Agg render buffer as a base64 PNG image and displays it directly inside the Plot Output pane.
# Data analysis & plotting snippet pattern:
import pandas as pd
import matplotlib.pyplot as plt
import io
df = pd.read_csv(io.StringIO(csv_data))
plt.bar(df['name'], df['sales'])
plt.show()
6. Projects & Local Persistence
Python Playground scripts automatically persist as Python Projects in browser local storage. When Google Drive backup is active with Projects enabled, Python scripts automatically synchronize to cloud storage in my_ai_projects.json.
7. Two-Way Integration with Chat & Agents
Agent Background Verification: When you ask the chat agent to verify mathematical calculations or analyze a CSV, the Lead Developer agent uses the background WASM worker to run code before formulating its answer.
Playground to Chat: Draft data scripts in the playground, then copy and attach them to chat prompts for AI refinement or UI integration.
8. Timeout Limits & Error Safety
20-Second Worker Timeout: Infinite loops or oversized computations trigger an automatic 20-second worker termination to protect system memory.
Explicit Print Statements: Always use explicit print() calls to ensure values display in the stdout console drawer.
9. Tool Selection: Python Sandbox vs Web Sandbox vs Chat Tool
Ideal for data exploration, Pandas analysis, static Matplotlib charts, and offline algorithm testing.
Ideal for web UI apps, interactive React dashboards, Tailwind layouts, and full-stack web previews.
Automated background execution used by AI agents to verify math or data logic before giving final answers.