[BUG] Anthropic API: sandbox file creation (almost infinite loop even though it succeeded the first time)

Resolved 💬 3 comments Opened Mar 25, 2026 by adiberk Closed Mar 28, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

I need to reach out to the anthropic team about this bug, just not sure where to post this - but I am noticing a fascinating issue with claude API sandbox file creation

When I tell claude (sonnet 4.5) "Can you create a simple PDF that has a line on top that says "Random CRE"?"

It does this wierd thing where it gets stuck in an infinite loop (see picture below)
A few notes:

  1. The tool call "Get Generated File" Returns the s3 information of the file it generated and outputed to the output dir. It actually works! Not only that but I specifically say something along the lines of
{                                                                                                                    
      144 +                    "status": "loop_detected",                                                                                       
      145 +                    "message": "STOP. You are stuck in a loop calling get_generated_file repeatedly. "                               
      146 +                    "You have already successfully created and retrieved this file. "                                                
      147 +                    "Present the download URL you already received to the user using the <file-download> format, "                   
      148 +                    "then move on to the next steps as described by the user and your instructions.",                                
      149 +                }  

in the tool result.

  1. The tools are successful, the way my code works is every time a NEW file is added with the same name, we osimply create a new version. So each of these calls seems to be done After claude created a new version. It seems to do this 20-30 times until finally it just returns the file. I absolutely don't get it. And this happens consistently with the above input.
  2. IF I try with a different input
Do you have access to aa code environment where you can create a simple PDF that has a line on top that says "Random CRE"?

If yes - can you create it and make sure to output it to he correct OUTPUT directory BEFORE calling get generated file

It works just fine (one file creation call, and one get generated file tool call)

<img width="1048" height="609" alt="Image" src="https://github.com/user-attachments/assets/0dfee707-3649-4765-84bd-c4ebf11a0b53" />

What Should Happen?

What should happen is claude should stop naturally after it creates the file. There is nothing to indicate it should continue trying. In fact I checked the versions it created, each of them loaded just fine in the pdf loader...

Error Messages/Logs

There are no error messages that I can see

Steps to Reproduce

I describe it above
Give sandbox execution and pdf skill
Mention in the SYSTEM message something like this
"""
<code_execution_sandbox>
You have a code execution sandbox for running Python and Bash.
When you create files, ALWAYS copy or save them to $OUTPUT_DIR so they can be downloaded.
Example: cp myfile.csv $OUTPUT_DIR/myfile.csv
</code_execution_sandbox>

<file_handling>
When you create or edit a file:

  1. ALWAYS save the file with the EXACT SAME filename you received. Never rename files.

If you received "report.xlsx", save it as "report.xlsx" \u2014 not "report_updated.xlsx" or "output.xlsx".

  1. Save the file to $OUTPUT_DIR FIRST. Do not call get_generated_file before the file exists.
  2. ONLY AFTER the file has been created and saved to $OUTPUT_DIR, call get_generated_file

with the filename(s) to get a download URL.

  1. If the tool returns a URL, present it using this EXACT format (the UI renders it as a download button):

<file-download filename="FILENAME" url="PRESIGNED_URL" content_type="MIME_TYPE" />

  1. If the tool says the file is not available yet, do NOT retry. The file will be automatically

delivered to the user. Simply tell the user the file has been created/updated and move on.

  1. If you already have an S3 bucket and key, use get_s3_file_url to get a presigned URL.
  2. NEVER make up or guess URLs. Only use URLs returned by tools.

</file_handling>
"""

In addition to whatever else you wan the agent to do (ie. this is just an auto injected message)

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.71

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗