More games at WuGames.ioSponsoredDiscover free browser games — play instantly, no download, no sign-up.Play

Python Sandbox

Run Python 3 in your browser via Pyodide (CPython on WebAssembly). Full stdlib, pip via micropip, persistent session, offline after first load. Zero install.

Python Sandbox - Run Python Code Online Free

Python is the world's most-taught programming language and the dominant tool of data science, machine learning, scientific computing, system scripting, and rapid web back-end work — but every beginner spends their first hour fighting a local installation: which interpreter (system Python, Anaconda, pyenv?), which venv strategy, which IDE, where pip lives. This sandbox skips all of that. The whole CPython interpreter has been compiled to WebAssembly by the Mozilla Foundation's Pyodide project (used in JupyterLite, the Pandas docs, and dozens of educational platforms) and loaded directly into your browser tab. After a one-time download of about 6 MB the first time you visit, every subsequent run is instant and works fully offline. You get Python 3.11+ with the complete standard library — os, sys, math, json, datetime, re, collections, itertools, functools, statistics, random — plus the option to load NumPy, Pandas, SciPy, Matplotlib, scikit-learn, sympy and other heavy data-science packages on demand via micropip. The execution context persists between runs (define a function, then call it later without re-defining), the file system is a virtual one in your browser, and the only things that don't work are network calls (urllib/requests/socket), native GUI toolkits (Tkinter, PyQt), and packages with C extensions that haven't been ported to WASM.

What is Python Sandbox?

Python Sandbox is an online Python interpreter that runs entirely in your browser. It uses Pyodide, which is CPython compiled to WebAssembly, allowing you to:

- Run Python code without installing anything
- Test code snippets instantly
- Learn Python interactively
- Debug and experiment with code
- Work offline after initial load

The sandbox supports most Python 3.x features and standard library modules.

How do I use this Python Sandbox?

Using the Python Sandbox is straightforward:

1. Wait for the Python environment to load (first time only)
2. Write or paste your Python code in the editor
3. Click 'Run Code' to execute
4. View the output in the console below
5. Use 'Clear' to reset the editor
6. Try example codes to learn Python basics

The environment persists between runs, so variables and functions remain available unless you reset.

What Python features are supported?

The sandbox supports most Python 3.x features:

- All basic Python syntax (variables, loops, conditionals)
- Functions and classes
- List, dict, set, tuple operations
- String manipulation and formatting
- File I/O (virtual filesystem)
- Most standard library modules
- Exception handling
- Decorators and generators
- List comprehensions

Some limitations:
- No network requests (fetch, urllib)
- No GUI libraries (tkinter, pygame)
- Limited threading support
- Some C-extension modules may not work

Is my code safe and private?

Yes, your code is completely safe and private:

- All code runs in your browser only
- No code is sent to any server
- No logging or tracking of your code
- Works completely offline after initial load
- Code is sandboxed and cannot access your system

The Pyodide environment is isolated and secure, running in a WebAssembly sandbox.

Can I install Python packages?

The sandbox comes with many common packages pre-installed. However, installing additional packages via pip is limited:

- Many pure-Python packages work
- Packages with C extensions may not work
- Use micropip for package installation

Example:
import micropip
await micropip.install('package-name')

Note: Not all PyPI packages are compatible with Pyodide.

Why does my requests.get() or urllib call fail with no internet error?

Because Pyodide runs inside the browser's WebAssembly sandbox, which by design has NO direct network socket access. The 'requests' library and urllib are built on raw TCP sockets, which the sandbox doesn't expose. Two workarounds: (1) Use pyodide.http.pyfetch, which wraps the browser's native fetch() API and works for HTTP/HTTPS. Replace 'requests.get(url).json()' with 'await pyodide.http.pyfetch(url).then(r => r.json())' (in async context). (2) Install the aiohttp-wasm or 'pyodide-http' patch package that monkey-patches requests to route through fetch under the hood. The remote server still needs to send CORS headers (Access-Control-Allow-Origin) or the browser will block the response — this is a browser security rule, not a Pyodide limitation. For local-only experimentation, simulate the API response with a dict and skip the HTTP call entirely.

Python Sandbox — Run Python 3 in your browser via Pyodide (CPython on WebAssembly). Full stdlib, pip via micropip, persistent session, of
Python Sandbox

Can I use NumPy or Pandas in this sandbox?

Yes. Both are pre-built Pyodide packages and load on demand via micropip — no compile step. Run this once in your code:

import micropip
await micropip.install(['numpy', 'pandas', 'matplotlib'])
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

The first install takes a few seconds (downloads ~10-20 MB of WASM-compiled binaries) but is then cached forever. After that, NumPy array operations run at near-native speed (Pyodide's NumPy is genuinely fast), Pandas DataFrames work normally, and Matplotlib renders SVG/PNG that you can display via plt.show() — Pyodide's display hooks render the image directly into the output panel. The full list of pre-built scientific packages includes scipy, scikit-learn, sympy, statsmodels, networkx, pillow, beautifulsoup4, lxml, regex, and many more. Check pyodide.org/en/stable/usage/packages-in-pyodide.html for the complete index.

How do I reset the interpreter or clear all variables between runs?

This is the single most common frustration with any persistent REPL: the execution context survives between runs, so a variable, function, import, or monkey-patch you defined earlier is still alive on the next run. That is intentional (it lets you build up state interactively, exactly like a Jupyter notebook), but it also means a stale global can silently poison later results. Clicking 'Clear' only wipes the editor text — it does NOT touch the Python namespace. To get a genuinely clean slate, click 'Reset Interpreter': it deletes every user-defined name from globals(), re-establishes the stdout/stderr capture, and gives you a fresh namespace WITHOUT re-downloading the ~6 MB Pyodide runtime (so it is instant, unlike reloading the page). You can also press Ctrl+Enter (Cmd+Enter on Mac) to run code straight from the keyboard. If you prefer to do it in code, run: for _n in list(globals()):
if not _n.startswith('__'): del globals()[_n] — but the button is faster and also resets the output buffers.

Why doesn't input() work, and how do I read stdin?

Searching 'python input() not working online' lands almost everyone here. Standard CPython input() blocks on a real terminal stdin, which the browser sandbox does not provide, so a plain input() call will raise an error or hang. There are three practical patterns in Pyodide: (1) Replace input() with the browser's own prompt dialog — Pyodide redefines the builtin so that input('Your name? ') pops up a JavaScript prompt() box and returns the typed string. This works out of the box for simple scripts. (2) For multi-line or piped input, pre-seed the data in your code instead of reading interactively: data = '''line1\nline2\nline3'''.splitlines() then iterate. (3) For testing code that calls input() repeatedly, monkey-patch it: responses = iter(['Alice', '42']); import builtins; builtins.input = lambda prompt='': next(responses). This feeds canned answers without any dialogs and is the cleanest way to demo or unit-test interactive scripts.

Can I upload a file, read it, or download a file my script generates?

Yes — Pyodide gives every tab a real in-memory virtual filesystem (MEMFS), so open(), os.path, pathlib, csv, json, and Pandas read_csv/to_csv all work normally against virtual paths. To get an external file IN, read it in JavaScript and write it to the FS, or use pyodide.FS.writeFile('/data.csv', bytes); then in Python just open('/data.csv'). To get a generated file OUT, write it normally (open('out.csv','w') or df.to_csv('out.csv')), then read the bytes back with pyodide.FS.readFile('out.csv') and trigger a browser download via a Blob. A common data-science flow: load a CSV into the FS, run pandas analysis, write a result CSV or a Matplotlib PNG, then download it. Everything lives only in your browser memory — nothing is uploaded to a server, and the files vanish when you reload (use Reset Interpreter to clear Python state without wiping the FS, or reload the page for a full reset).

What are the code examples for?

The code examples help you:

- Learn Python basics quickly
- See working code patterns
- Understand Python syntax
- Get started with common operations

Examples cover:
- Hello World (basic print)
- Loops (for, while)
- Functions (definition and calls)
- Lists and operations
- Dictionaries and data structures
- Classes and object-oriented programming

Click any example to load it into the editor and run it!

Key Features

  • Run Python 3.x code in browser
  • Run instantly from the keyboard with Ctrl+Enter (Cmd+Enter on Mac)
  • Reset Interpreter button for a clean namespace without reloading
  • Matplotlib figures render directly in the output panel
  • No installation or signup required
  • Instant code execution with output
  • Syntax highlighting and code editor
  • Multiple code examples to learn from
  • Error messages and stack traces
  • Execution time tracking
  • Download code as .py file
  • Clear and reset functionality
  • Works offline after initial load
  • 100% client-side - code never leaves your browser
  • Dark mode support
  • Mobile-friendly responsive design
  • Powered by Pyodide (CPython in WebAssembly)