- Hosted shell: Azure OpenAI provisions and manages a sandboxed container for the request.
- Local shell: You execute the model’s
shell_callactions in your own runtime and return the results.
Running arbitrary shell commands can be dangerous. Always sandbox execution, apply allow lists or block lists where possible, and log tool activity for auditing.
The shell tool requires an Azure OpenAI API version that supports it, and a model deployment that supports the Responses API. Confirm support for your target API version before you deploy to production.
Prerequisites
- An Azure OpenAI model deployed that supports the Responses API and the shell tool.
- An authentication method:
- API key, or
- Microsoft Entra ID.
- Install the client library for your language:
- Python:
pip install openai azure-identity - JavaScript/TypeScript:
npm install openai @azure/identity - Java: Add
com.openai:openai-javaandcom.azure:azure-identityto your project.
- Python:
- For REST examples, set
AZURE_OPENAI_API_KEY(API key flow) orAZURE_OPENAI_AUTH_TOKEN(Microsoft Entra ID flow).
Run your first command with hosted shell
Hosted shell is the fastest way to get started. Set the environment tocontainer_auto to let Azure OpenAI provision and manage a container for the request. The model decides whether to call the tool based on your prompt.
In the examples that follow, replace gpt-5.5 with the name of your own model deployment.
Hosted runtime details
The hosted container provides a managed Linux environment for each request or container session:- The runtime is based on
Debian 12and might change over time. - The default working directory is
/mnt/data. This directory is always present and is the supported path for user-downloadable artifacts. - Python
3.11is preinstalled. - Hosted shell doesn’t support interactive TTY sessions, and commands don’t run with
sudo. - Hosted containers don’t have outbound network access.
Reuse a container across requests
For iterative workflows, create a container once and reference it in later Responses API calls. The container keeps files and state between requests while it’s active. First, create the container.- Python
- JavaScript
- Java
- REST
- Python
- JavaScript
- Java
- REST
container_id and the previous_response_id from the prior response.
Run commands in local shell mode
In local shell mode, you execute the model’s commands in your own runtime instead of a hosted container. Use this mode when you need full control over the execution environment, filesystem access, or existing internal tooling. Set the environment tolocal. The model returns shell_call items that describe the commands to run.
shell_call items, run the requested commands, capture the output, and return the results as shell_call_output in your next request. The following executor captures stdout, stderr, and the exit outcome, and handles timeouts.
Shell output in responses
Hosted shell and local shell use the same output item types. Each shell run is represented by a pair of items:shell_call: the commands the model requests.shell_call_output: the command output and exit outcome.
shell_call item:
shell_call_output item:
shell_call includes max_output_length, include the same value on the shell_call_output. If a command exceeds your execution timeout, return a timeout outcome and include any partial output you captured.
Download artifacts
Hosted shell can produce downloadable files. To retrieve artifacts, write them under/mnt/data, then download them by using the same container and files APIs used by Code Interpreter.
Data retention and container lifecycle
- A hosted container session ends after 20 minutes of idle time.
- A hosted container is deleted one hour after it’s created. All data stored in the container is removed when the container is deleted.
Handle common errors
- Timeouts: If a command exceeds your execution timeout, return a
timeoutoutcome and include any partial output you captured. - Truncated output: When
max_output_lengthis present on ashell_call, set the same value on theshell_call_output. - Interactive commands: Shell tool execution is non-interactive. Don’t rely on commands that prompt for input.
- Non-zero exits: Preserve output from non-zero exits so the model can reason about recovery steps.