Skip to main content

Overview

Agent runs can produce files such as CSV, JSON, JSONL, and reports in the sandbox. When code the model runs in the sandbox tool writes a file and delivers it with the share_file tool, the response output array includes a share_file item. The file content is not returned inline — retrieve it separately with the response files endpoints, using the response id.

Produce a file

Give the agent the sandbox tool and ask it to write a file. Here it generates a CSV of the latest AI news. Keep the resulting response.id — you use it to list and download the file.
For runs that take a while, submit with background=true and poll before listing files. See Background mode.

List a response’s files

GET /v1/responses/{id}/files Use the response id from the run above to list the files it produced.
FieldTypeDescription
idstringFile identifier, used to download; distinct from response id.
filenamestringName the sandbox gave the file.
bytesintegerFile size in bytes.
created_atintegerUnix timestamp when created.
objectstringAlways file.

Download a file

GET /v1/responses/{id}/files/{file_id}/content Use the file id to download its content. The file id is distinct from the response id.
This endpoint returns raw file bytes, not JSON. The response includes a Content-Type matching the file and a Content-Disposition: attachment header carrying the original filename.

Full example

Create a run that writes a file, then list and download everything it produced.
Python

Next Steps

Sandbox

Background mode

Wide Research