Follow Discord
Sweep 22 Oct 2026 · 21:04Z Build v2.1.309 528 read Stable v2.1.308 Latest v2.1.309 Next v2.1.309 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

code-execution-tool changedagents-and-tools/tool-use/code-execution-tool

Nearest release: v2.1.239, published 2 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+12added
Lines−18removed
From line 42 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits23to this page, all time

The whole hunk

from line 42, old and new numbered
/
lines
from line 42
4242* `code_execution_20260120` adds REPL state persistence and [programmatic tool calling](https://platform.claude.com/docs/en/agents-and-tools/tool-use/programmatic-tool-calling) from within the sandbox. Claude Haiku 4.5 accepts the `code_execution_20260120` and `code_execution_20260521` tool types, but programmatic tool calling and the REPL state persistence that depends on it aren't available on it, so the newer versions behave like `code_execution_20250825` there.
4343* `code_execution_20260521` is the same runtime as `code_execution_20260120`. The difference is that the tool description tells Claude about the 90-second wall-clock limit on each Python cell in programmatic tool calling, so Claude can budget long-running cells. A cell that exceeds the limit returns a normal code execution result with a non-zero `return_code` and a `detection_timeout` status message in its output. This is separate from the `execution_time_exceeded` [error code](https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool#errors), which the API returns when a whole tool invocation exceeds the maximum execution time.
4444 
45All three tool versions are generally available and don't require an `anthropic-beta` header. The legacy code execution beta headers remain valid opt-ins.
45None of the three tool versions requires an `anthropic-beta` header. The legacy code execution beta headers remain valid opt-ins.
4646 
4747The examples on this page use `code_execution_20250825`, which covers the Bash and file operations they demonstrate and behaves the same way on every model in the table; use `code_execution_20260120` or later when you need programmatic tool calling or REPL state persistence. The current [web search](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool) and [web fetch](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool) tools (`web_search_20260209`, `web_fetch_20260209`, and later) require `code_execution_20260120` or later as their code execution version.
4848 
from line 324
324324 
325325 ```bash CLI
326326 # First, upload a file and capture the file ID
327 FILE_ID=$(ant files upload \
328 --file ./data.csv \
329 --transform id --raw-output)
327 FILE_ID=$(ant files upload --file ./data.csv --transform id --raw-output)
330328 
331329 # Then use the file_id with code execution
332330 ant messages create <<YAML
from line 503
505503 ```
506504 
507505 ```php PHP
508 // The PHP SDK exposes the Files API under the beta namespace; field names can differ from other SDKs.
509506 $client = new Client();
510507 
511508 // Upload a file
512 $fileObject = $client->beta->files->upload(
509 $fileObject = $client->files->upload(
513510 file: FileParam::fromResource(fopen('data.csv', 'r')),
514511 );
515512 
516513 // Use the file_id with code execution
517 $response = $client->beta->messages->create(
514 $response = $client->messages->create(
518515 model: Model::CLAUDE_OPUS_5,
519516 maxTokens: 4096,
520 betas: [AnthropicBeta::FILES_API_2025_04_14],
521517 messages: [
522518 [
523519 'role' => 'user',
524520 'content' => [
525 BetaTextBlockParam::with(text: 'Analyze this CSV data'),
526 BetaContainerUploadBlockParam::with(fileID: $fileObject->id),
521 TextBlockParam::with(text: 'Analyze this CSV data'),
522 ContainerUploadBlockParam::with(fileID: $fileObject->id),
527523 ],
528524 ],
529525 ],
530 tools: [new BetaCodeExecutionTool20250825()],
526 tools: [new CodeExecutionTool20250825()],
531527 );
532528 
533529 echo json_encode($response), PHP_EOL;
from line 803
807803 ```
808804 
809805 ```php PHP
810 // The PHP SDK exposes the Files API under the beta namespace; field names can differ from other SDKs.
811806 $client = new Client();
812807 
813808 // Request code execution that creates files
814 $response = $client->beta->messages->create(
809 $response = $client->messages->create(
815810 maxTokens: 4096,
816811 messages: [
817812 [
from line 815
820815 ],
821816 ],
822817 model: Model::CLAUDE_OPUS_5,
823 betas: [AnthropicBeta::FILES_API_2025_04_14],
824 tools: [new BetaCodeExecutionTool20250825()],
818 tools: [new CodeExecutionTool20250825()],
825819 );
826820 
827821 /**
from line 823
829823 *
830824 * @return list<string>
831825 */
832 function extractFileIds(BetaMessage $response): array
826 function extractFileIds(Message $response): array
833827 {
834828 $fileIds = [];
835829 foreach ($response->content as $block) {
from line 843
849843 
850844 // Download the created files
851845 foreach (extractFileIds($response) as $fileId) {
852 $fileMetadata = $client->beta->files->retrieveMetadata($fileId);
853 $fileContent = $client->beta->files->download($fileId);
846 $fileMetadata = $client->files->retrieveMetadata($fileId);
847 $fileContent = $client->files->download($fileId);
854848 
855849 file_put_contents($fileMetadata->filename, $fileContent);
856850 echo "Downloaded: {$fileMetadata->filename}\n";
Feedback