Skip to main content
Items marked (preview) in this article are currently in public preview. This preview is provided without a service-level agreement, and we don’t recommend it for production workloads. Certain features might not be supported or might have constrained capabilities. For more information, see Supplemental Terms of Use for Microsoft Azure Previews.
This article shows how to add a shell tool to a Microsoft Foundry toolbox and make it available to a Microsoft Foundry prompt agent through the toolbox’s Model Context Protocol (MCP) endpoint. The shell toolbox tool provides access to a sandboxed, network-isolated container that Microsoft Foundry provisions and manages for you when you create a toolbox version. You don’t need to deploy or manage container infrastructure yourself. Use the shell toolbox tool when your agent needs to:
  • Inspect the container runtime environment, such as the Python version, installed packages, or working directory.
  • Run scripts and process files in an isolated execution environment.
  • Automate tasks that require shell access without exposing your network.
The shell toolbox tool is a toolbox-level tool. You can add it only when creating a toolbox version by using toolboxes.create_version(tools=[...]). You can’t add ShellToolboxTool directly to PromptAgentDefinition(tools=[...]). Instead, the prompt agent accesses the shell tool through an MCPTool that’s configured to connect to the toolbox’s MCP endpoint.
Shell toolbox tool and Responses API shell tool are different tools.Although they have similar names, they’re used in different ways:
  • ShellToolboxTool is added to a toolbox and accessed by agents through the toolbox’s MCP endpoint.
  • The Responses API shell tool is provided directly in a Responses API request and doesn’t require a toolbox or MCP endpoint.
Learn more about the Responses API shell tool.

Prerequisites

  • A Foundry project with a deployed model.
  • Azure CLI installed and authenticated: az login
  • Python SDK installed at the required minimum version: pip install "azure-ai-projects>=2.6.0" azure-identity

Create a toolbox with the shell tool

Create a toolbox version that includes ShellToolboxTool. Foundry provisions the container environment automatically when you use ToolboxShellContainerAutoEnvironment. Set allow_preview=True on the client because ShellToolboxTool is a preview feature. The tools=[shell_tool] parameter populates the toolbox’s tool list — this list is separate from an agent’s tools list, which accepts only agent-level tools like MCPTool. ShellToolboxTool supports the following parameters:
The output includes the version number. Copy it. You use it in the next step to build the MCP endpoint URL.

Connect a prompt agent to the toolbox

Create a prompt agent that reaches the shell tool through MCPTool. The agent authenticates to the toolbox MCP endpoint by using an Entra token. After you create the agent version, configure the agent endpoint to route traffic to that version. Replace TOOLBOX_VERSION with the version printed in the previous step.

Send a request and read the output

Send a request to the agent and iterate over the response output items. The Responses API returns structured output items as the model interacts with the MCP server. Two item types are relevant for the shell tool:
  • mcp_list_tools: The MCP server sends the list of available tools at the start of the session. Use this item to confirm that the shell tool is reachable.
  • mcp_call: Each call to the shell tool. The item includes the tool name, the arguments the model passed, the command output, and any error.
The exact tool name and container runtime depend on the provisioned environment.

Container environment options

The environment parameter on ShellToolboxTool controls how the container is provisioned.

Auto-provisioned container

ToolboxShellContainerAutoEnvironment is the default choice. Foundry provisions and manages the container for you — no container image or registry configuration required.
ToolboxShellContainerAutoEnvironment accepts these optional properties: The following snippet sets a 4 GB memory limit:

Use an existing container

ToolboxShellContainerReferenceEnvironment lets you point the shell tool at a container you already provisioned. Pass the container’s ID as container_id — that’s the only property this class takes.

Network isolation

The shell tool’s container runs without outbound network access by default. This behavior is documented: when you omit network_policy on ToolboxShellContainerAutoEnvironment, the service defaults to disabled outbound access. This default prevents the shell tool from making outbound calls to arbitrary endpoints and limits the impact of any command the model issues. The toolbox shell tool currently exposes one network policy class:
  • ToolboxShellNetworkPolicyDisabled (wire value `“disabled”“): Disables outbound network access from the container. This policy matches the service default.
Unlike the code-interpreter container policy, the toolbox shell tool doesn’t offer an allowlist option. "disabled" is the only available network policy.
To set the policy explicitly rather than relying on the default:
For broader toolbox network isolation, including how toolbox traffic flows when your project uses a virtual network and private link, see Network isolation for a toolbox in Microsoft Foundry.

Clean up resources

Delete the agent version and the toolbox when you no longer need them.