← LearnClaude.ai · Tools

How to Create Files with Claude Code Execution

To create files with Claude code execution, enable 'Code execution and file creation' in Settings > Features on claude.ai, then describe the file you want in a new conversation. Claude writes and runs the code in a secure sandbox and returns a downloadable link directly in the chat.

To create files with Claude code execution, enable the feature in your claude.ai Settings, start a conversation, and describe the file you need. Claude writes a script, runs it in a secure sandboxed environment, and delivers a download link — no local software or coding knowledge required. This works for Excel (.xlsx), Word (.docx), PowerPoint (.pptx), PDFs, chart images, and more.

What Is Claude Code Execution and File Creation?

Code execution and file creation gives Claude a secure, sandboxed computing environment where it can write and run code, manipulate files, and produce downloadable documents — all without leaving the conversation. The sandbox runs Bash commands and supports multiple programming languages. Claude autonomously writes the scripts, executes them, and returns results or downloadable files directly in the chat.

This is different from Claude's Artifacts feature, which renders interactive HTML, React, Markdown, SVG, and Mermaid diagrams inside the conversation. Code execution is for real binary file formats and actual computation on data — things that require running Python libraries like openpyxl, pandas, or matplotlib.

According to Anthropic's official documentation on creating and editing files with Claude, the feature is available on Free, Pro, Max, Team, and Enterprise plans with no extra subscription charge beyond the plan itself.

How Do You Enable Code Execution on claude.ai?

  1. Sign in to your account at claude.ai.
  2. Open Settings by clicking your account icon or the gear icon.
  3. Navigate to Features (sometimes labeled Capabilities).
  4. Toggle 'Code execution and file creation' to ON.
  5. Start a new conversation and ask Claude to create a file or run code.

Team plans: The feature is enabled by default at the org level. An owner can disable it in Organization Settings > Capabilities.

Enterprise plans: The feature is enabled by default, but network egress is toggled OFF by default. An owner can change egress settings in Organization Settings > Capabilities.

How Do You Create an Excel File with Claude?

Here is a concrete beginner example. Say you want a monthly personal budget tracker with no spreadsheet skills required.

Sample prompt:

Create an Excel spreadsheet for a monthly personal budget. Include rows for: Salary (income), Rent, Groceries, Utilities, Entertainment, and Savings. Add a 'Total Expenses' row and a 'Remaining Balance' row that subtracts expenses from salary. Use currency formatting. Pre-fill example values so I can see how it works.

What happens: Claude writes a Python script using openpyxl, executes it in the sandbox, and a download link for a budget.xlsx file appears in the chat. The file contains labeled rows, example dollar values, a SUM formula for Total Expenses, and a Remaining Balance formula — all with USD currency formatting.

This eliminates the need to know Excel formulas or formatting. Claude handles the technical file creation so you get a functional, professional document immediately.

How Do You Create a Word Document from an Uploaded CSV?

You can also upload data files and have Claude transform them. File uploads and downloads are both capped at 30 MB per file. Large PDFs exceeding this limit can still be passed directly into the computing environment for processing without consuming the conversational context window.

Sample prompt:

I'm uploading a CSV of customer orders (columns: Order ID, Customer Name, Product, Quantity, Price). Please convert it to a formatted Word document with a table. Add a title 'Customer Orders — Q2 2026' and make the header row bold.

Claude reads the CSV, writes a Python script using python-docx, builds the table, and provides a .docx download link. Users without Python or Word macro knowledge get polished, shareable documents from raw data files in seconds.

How Do You Use Code Execution via the Claude API?

For developers building automated pipelines, the feature is exposed as a tool. Include the beta header code-execution-2025-08-25 in your API request and add the tool definition for code_execution_20250825. A newer version, code_execution_20260120, adds REPL state persistence and programmatic tool calling from within the sandbox, but is limited to Opus 4.5+ and Sonnet 4.5+.

Here is a minimal API tool definition example using claude-sonnet-4-5-20250929:

{
  "model": "claude-sonnet-4-5-20250929",
  "tools": [
    {
      "type": "code_execution_20250825"
    }
  ],
  "messages": [
    {
      "role": "user",
      "content": "Upload this CSV and return a formatted Excel pivot table."
    }
  ]
}

See the Anthropic API documentation for the code execution tool for full request schemas and beta header details.

REPL state persistence (available in code_execution_20260120) means variables and state persist across multiple code execution calls in a single session — useful for multi-step data pipelines where you clean data in one turn and visualize it in the next.

When Should You Use Code Execution vs. Artifacts vs. Plain Text?

Situation Best Tool Why
Need a downloadable Excel, Word, or PowerPoint file Code Execution Only code execution produces real binary file formats
Want an interactive React component or HTML page in the chat Artifacts Artifacts render interactive outputs without a file download
Need to run pandas/matplotlib on uploaded CSV data Code Execution Requires actual computation and library calls
Just want a code snippet or template to run yourself Plain text generation No execution or file output needed; no sandbox required
Building an automated agent pipeline at scale API code execution tool Programmatic control, REPL persistence, multi-tool integration
Processing sensitive data with no external network access Code Execution (Enterprise, egress OFF) Isolated container keeps computation off the internet

What Are the Most Common Pitfalls and How Do You Fix Them?

Broken formulas in generated Excel files

Be explicit about cell references and formula logic in your prompt. For example: "In B3, use =B2*1.2 for Year 2 revenue; use SUM() for totals, not manual addition." Claude Sonnet 4.5 or newer models deliver more consistent formula accuracy and multi-sheet reference handling.

Package installation fails with a 'no internet' error

Enterprise plans default to network egress OFF. If you need external packages from PyPI, ask your organization owner to enable network egress to package managers in Organization Settings > Capabilities. If egress must stay off, stick to pre-installed packages.

Files don't appear as downloadable artifacts

File creation routes through the computing environment rather than the older Artifacts system. For Excel, Word, and PowerPoint, look for the download link that appears in the chat after code execution completes — not in the Artifacts panel. Ensure the toggle is ON in Settings.

Claude enters an error-retry loop, burning API calls

In your system prompt, explicitly instruct: "If code execution fails twice for the same reason, stop immediately and ask the user for clarification rather than retrying." TDD-style prompting — asking Claude to write validation checks first — also helps catch structural issues early.

Prompt injection via uploaded files

Malicious content in uploaded files can attempt to inject instructions that cause Claude to run unintended code. Monitor Claude's actions during sessions, only enable network egress when necessary, and use allowlists for Team and Enterprise deployments.

What File Formats and Use Cases Does This Support?

  • Excel (.xlsx): Budget trackers, financial forecasts with live formulas and embedded charts, pivot tables from CSV data
  • Word (.docx): Reports with formatted tables, executive summaries, documents converted from raw data files
  • PowerPoint (.pptx): Slide decks with key findings from survey data, automatically generated from research results
  • PNG/chart images: Bar charts, line charts, and visualizations generated from uploaded datasets using matplotlib
  • PDF processing: Large PDFs can be passed directly into the computing environment without consuming the context window
  • Code testing: Write unit tests, execute them in the sandbox, and receive a pass/fail report with suggested fixes

For a deeper look at professional output quality, see Anthropic's guide to creating professional results with Claude Sonnet 4.5.

Frequently asked questions

Is code execution and file creation available on the free Claude plan?

Yes. The feature is available on Free, Pro, Max, Team, and Enterprise plans with no extra charge beyond the plan itself.

What file formats can Claude create with code execution?

Claude can produce Excel (.xlsx), Word (.docx), PowerPoint (.pptx), PDF, and image files like PNG charts, among other formats generated by Python libraries in the sandbox.

What is the file size limit for uploads and downloads?

Both uploads and downloads are capped at 30 MB per file. Large PDFs can be passed directly into the computing environment without going through the context window.

How is code execution different from Claude Artifacts?

Artifacts render interactive outputs like HTML, React, SVG, and Mermaid diagrams inside the conversation. Code execution runs actual scripts to produce downloadable binary files (Excel, Word, PowerPoint) and perform real computations on data.

Can I use code execution via the Claude API?

Yes. Include the beta header 'code-execution-2025-08-25' and add the tool definition for 'code_execution_20250825'. A newer version, 'code_execution_20260120', adds REPL state persistence and is available on Opus 4.5+ and Sonnet 4.5+.

Why is network egress disabled by default on Enterprise plans?

Enterprise plans default to network egress OFF to keep computation isolated within the secure container, preventing the sandbox from reaching external services. Organization owners can enable egress in Organization Settings > Capabilities.

Go deeper

Code Execution & File Creation is one of 85 features in Claude Master — the independent, always-current manual with worked examples, the pitfalls, and the workflows that make Claude pay.

Get Claude Master — founding price

Independent product. Not affiliated with or endorsed by Anthropic. "Claude" is a trademark of Anthropic, used here only to describe the subject of this guide.

CLAUDEMASTER
An independent publication.
Independent product. Not affiliated with or endorsed by Anthropic. “Claude” is a trademark of Anthropic, used here only to describe the subject of this manual.
© 2026 Claude Master — All rights reserved.