Interactive Code Execution with Artifacts

I've been wanting a way to let readers run code directly in blog posts — not just read about it. Today I'm shipping interactive artifacts powered by Anthropic's Code Execution Tool.
Every code block below runs in an isolated Linux container on Anthropic's infrastructure. No local setup needed, no browser sandboxing tricks. Real Python, real output.
How It Works
The ::code-runner component sends your code (or a prompt) to Claude via the Messages API with the code_execution tool enabled. Claude runs it in a sandboxed container and streams back stdout, stderr, and any generated files.
The container persists between runs within the same artifact, so you can build up state across multiple executions.
Example 1: Fibonacci Sequence
A classic starting point. Hit "Run" to see the first 15 Fibonacci numbers.
Example 2: Data Visualization
This one generates a matplotlib chart. The resulting PNG renders inline below the output.
Example 3: Quick Math
Edit the code and re-run to experiment.
Under the Hood
The artifact system uses three Anthropic beta APIs:
- Code Execution (
code-execution-2025-08-25) — runs code in isolated containers - Files API (
files-api-2025-04-14) — downloads generated files (images, HTML, etc.) - Skills API (
skills-2025-10-02) — optional document generation capabilities
Each execution streams results via SSE, so you see output as it happens rather than waiting for the full response.
The container has Python with common libraries pre-installed (numpy, pandas, matplotlib, etc.) but no internet access — it's fully sandboxed.
What's Next
This is the foundation for more interactive content. I'm exploring adding artifact execution to the chat interface and supporting more languages beyond Python.
If you have ideas for interactive examples you'd like to see, let me know on X.
Free Printable Language Arts Sheets for Kids — Sight Words, Parts of Speech, Homophones, and More
Free printable PDF worksheets for kids — Dolch sight words, parts of speech, punctuation, homophones, contractions, alphabet chart, and handwriting practice. Download, print, and learn.
Free Printable Telling Time Worksheet for Kids — Clock Reference & Practice Sheet
Free printable PDF worksheet for kids learning to tell time — analog clock reference with hour and minute hands, common times, and 12 practice clocks. Download, print, and learn.