An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
For Foundry Prompt Agents and the Code Interpreter tool, the behavior being observed is expected and differs from the classic Assistants API.
- Behavior difference vs. classic Assistants API
- In classic Azure OpenAI Assistants, Code Interpreter output files are stored as durable “files” and exposed via file IDs that can be retrieved later through the Files API.
- In Azure AI Foundry agents (Prompt Agents / Hosted Agents), Code Interpreter runs in a sandboxed container session. Files created there are container-scoped and exposed as sandbox paths (for example,
sandbox:/mnt/data/...) plus container/file metadata. These are not automatically promoted to durable “data files” and are expected to be temporary. - The sandbox is a dynamic session with a limited lifetime and is isolated per session. Files in that sandbox are therefore ephemeral by design.
Relevant behaviors:
- Code Interpreter runs in a Microsoft-managed sandbox using dynamic sessions in Azure Container Apps.
- Each session is isolated and has a limited lifetime (idle timeout and max duration).
- Files in the sandbox are accessible to the Python runtime and can be returned as downloadable outputs, but they are not guaranteed to persist beyond the session.
[Context: Code Interpreter tool for Microsoft Foundry agents – Sandboxed execution environment]
- How to access files generated by Code Interpreter in Prompt Agents
For Prompt Agents / Foundry agents, the supported pattern is:
- When Code Interpreter generates a file, the agent response includes annotations with container/file metadata (for example,
content[]._meta.container_idand file IDs/names). - Use the container and file APIs to list and download those files while the container is still active.
Typical flow (REST):
- List files in the container
- Extract
container_idfrom thetools/callresponse metadata. - Call the Container Files API:
GET {project_endpoint}/containers/{container_id}/files?api-version=v1 Authorization: Bearer {token} - The response returns file names and IDs for all files in that container.
- Download a specific file
- Use the file name/ID from step 1 with the File API download endpoint (as documented under the File API download endpoint for Foundry).
This is the recommended way to retrieve Code Interpreter outputs for Foundry agents.
[Context: Curate intent-based toolbox in Foundry (preview) (rest-api)] [Context: Code Interpreter tool for Microsoft Foundry agents (csharp)] [Context: Code Interpreter tool for Microsoft Foundry agents (python)]
- Persistence model and production recommendation
- The container sandbox is not a durable storage mechanism. Files there are tied to the session and will expire when the session/container is cleaned up.
- There is no indication in the provided context that Foundry agents automatically convert these container files into durable, globally addressable file IDs like the classic Assistants Files API.
For a production chat application that needs persistent access to generated files (charts, images, CSVs) from chat history, the recommended pattern based on the documented APIs is:
- Immediately after receiving a response that includes Code Interpreter file annotations:
- Parse the container/file metadata from the response.
- Call the Container Files API to list and then the File API to download the relevant files.
- Store the downloaded files in an application-controlled persistent store:
- For example, Azure Blob Storage, a database, or any other long-term storage.
- Persist the mapping between the chat message (or conversation ID) and the stored file URL/path in the app’s own data model.
- When rendering chat history:
- Use the app’s own persistent URLs/paths to serve those files to users.
This pattern ensures durability and user access independent of the sandbox lifecycle.
- Memory and vector stores vs. file persistence
- The “memory” attached to agents and the vector stores used for RAG are separate concepts from Code Interpreter’s sandbox file system.
- The context only indicates that Code Interpreter can access attached files and generate new files in the sandbox; it does not state that generated files are automatically stored into memory or vector stores.
- Therefore, not seeing generated files “saved in memory” is consistent with the documented behavior. Memory/vector stores are for knowledge and retrieval, not for automatic file persistence.
- Summary
- Yes, ephemeral sandbox file behavior for Code Interpreter outputs in Foundry agents is expected.
- To persist files for production use:
- Use container/file APIs to download outputs as soon as they are generated.
- Store them in application-managed durable storage.
- Reference those stored locations in chat history.
- Memory and vector stores do not automatically capture or persist Code Interpreter-generated files.
References:
- Code Interpreter tool for Microsoft Foundry agents (rest)
- Curate intent-based toolbox in Foundry (preview) (rest-api)
- Code Interpreter tool for Microsoft Foundry agents (csharp)
- Code Interpreter tool for Microsoft Foundry agents (python)
- Azure OpenAI Assistants Code Interpreter (Preview)
- Azure OpenAI Assistants Code Interpreter (Preview) (classic)