How to download a file from OpenAI sandbox created by an agent

I am creating an application that will send a pdf file to an Agent LLM and return an updated version of the pdf. I am currently getting the agent to give me a sandbox link that looks like
[Download AP_CV.pdf](sandbox:/mnt/data/AP_CV.pdf) in response.final_output. How can I download this file via my python backend. I requested the agent to give me a file id so i can download it with OpenAI().files module but the agent is hallucinating a file id and also it is hallucinating the base64 encoded string of the file so i am unable to reconstruct the file.
The model says the file is available in the sandbox but I am unable to find the file with OpenAI().files.list() .

Code interpreter after Assistants does not provide files via the files endpoint. It has files in a “container” that is an expiring code interpreter environment.

https://platform.openai.com/docs/guides/tools-code-interpreter#containers

For the Responses API, this forum reply has a quick ‘chat’ Python script with some helpers which shows automatic retrieving of any offered files by the AI. Indeed download must be automatic and immediate for you to then persist for the user, because of the lack of container persistence.

1 Like