The Rust Playground
The Rust Playground (https://play.rust-lang.org) is an official browser-based environment for writing, compiling, executing, formatting, linting, and sharing Rust code snippets without installing anything locally.
Capabilities of the Rust Playground
The Playground runs a sandboxed Linux container on the backend with the official Rust toolchains and the top 100 most-downloaded crates from crates.io pre-installed:
| Feature | Options Available in the Playground UI |
|---|---|
| Execution Mode | Run (cargo run), Build (cargo build), Test (cargo test), or compile-only |
| Release Channel | Stable, Beta, or Nightly |
| Build Profile | Debug (opt-level = 0, fast build) or Release (opt-level = 3, full optimizations) |
| Edition Selection | 2024, 2021, 2018, or 2015 (under the Config / advanced menu) |
| Output Targets | Program stdout/stderr, ASM (Assembly), LLVM IR, MIR (Mid-Level IR), HIR, or Wasm |
| Integrated Tools | Rustfmt (format code), Clippy (run linter), Miri (check unsafe code for Undefined Behavior), Expand macros |
| Sharing | Generates a permanent shareable URL + GitHub Gist (Share button) |
Using Top Ecosystem Crates in the Playground
In addition to the standard library (std, core, alloc), the Playground pre-compiles the 100 most popular crates on crates.io—including serde, serde_json, rand, regex, tokio, itertools, rayon, anyhow, thiserror, bytes, and chrono. You can import any of them directly with use without editing a Cargo.toml file:
use rand::Rng;
fn main() {
let mut rng = rand::rng();
let roll: u8 = rng.random_range(1..=6);
println!("Rolled a {roll}");
}
Rolled a 4
Inspecting Compiler Output: Assembly, LLVM IR, and MIR
Instead of clicking Run, opening the ... mode menu next to the Run button lets you inspect how the compiler lowers your code:
Playground Execution Modes:
[ Run ] ▼
├── Run (Compiles and executes `main()`, showing stdout and stderr)
├── Build (Compiles without executing)
├── Test (Runs all `#[test]` functions in the snippet)
├── ASM (Displays generated x86_64 assembly instructions)
├── LLVM IR (Displays LLVM Intermediate Representation)
├── MIR (Displays Rust's Mid-Level IR control-flow graph)
└── Wasm (Emits WebAssembly output)
Tip: When inspecting ASM or LLVM IR in the Playground, always switch the profile dropdown from Debug to Release (and replace
fn main()with apub fntaking parameters) so LLVM's inlining and dead-code elimination show the true optimized machine instructions rather than unoptimized debug scaffolding.
Checking unsafe Code with Miri in the Playground
Under the Tools dropdown menu, selecting Miri executes your program inside rustc's abstract machine interpreter rather than running it as a native CPU binary. Miri tracks pointer provenance, memory initialization per byte, alignment, and stacked/tree borrows—catching Undefined Behavior in unsafe code that might accidentally appear to "work" on a real CPU:
fn main() {
let mut x = 10;
let ptr = &mut x as *mut i32;
unsafe {
*ptr = 20;
println!("Valid raw pointer write verified by Miri: {}", *ptr);
}
}
Valid raw pointer write verified by Miri: 20
Expanding Macros in the Playground
Selecting Tools -> Expand macros runs rustc -Zunpretty=expanded on your snippet and displays the exact Rust code generated by macros like println!, vec!, or #[derive(Debug, Clone, PartialEq)].
Limitations of the Sandbox Environment
Because the Playground runs inside an isolated, time-limited container:
- No outbound network access: Opening external TCP/HTTP connections (
TcpStream::connect) is blocked by the container sandbox. - Execution time and memory limits: Infinite loops or programs that exceed a few seconds of CPU time or the container RAM cap are terminated automatically with
SIGKILL. - Ephemeral filesystem: Files written to
/tmpor the current working directory exist only for the duration of that single run.