
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.
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.
A classic starting point. Hit "Run" to see the first 15 Fibonacci numbers.
This one generates a matplotlib chart. The resulting PNG renders inline below the output.
Edit the code and re-run to experiment.
The artifact system uses three Anthropic beta APIs:
code-execution-2025-08-25) — runs code in isolated containersfiles-api-2025-04-14) — downloads generated files (images, HTML, etc.)skills-2025-10-02) — optional document generation capabilitiesEach 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.
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.