Follow Discord
Sweep 20 Nov 2026 · 19:55Z Build v2.1.330 547 read Stable v2.1.323 Latest v2.1.330 Next v2.1.330 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

self-hosted-sandboxes-custom-tools changedmanaged-agents/self-hosted-sandboxes-custom-tools

Nearest release: v2.1.328, published 7 hours after this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.

Recorded here
Lines+32added
Lines−6removed
From line 42 where the diff opens
First seen 2 Oct 2026 this site's first read of the page
Recorded edits21to this page, all time

The whole hunk

from line 42, old and new numbered
/
lines
from line 42
4242The environment key authorizes posting custom tool results, so your Claude API key stays off the worker host.
4343 
4444<Note>
45 To serve custom tools, you need the SDK worker. The `ant` CLI worker has no way to register a custom tool implementation. In the sandbox-per-session pattern, [run the SDK worker inside the sandbox](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#run-the-sdk-worker-inside-the-sandbox).
45 To serve custom tools, you need the SDK worker. The `ant` CLI worker has no way to register a custom tool implementation. In the sandbox-per-session pattern, [run the SDK worker inside the sandbox](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-per-session#run-the-sdk-worker-inside-the-sandbox).
4646</Note>
4747 
4848## Serve a custom tool
from line 68
6868 </Step>
6969 
7070 <Step title="Register the implementation with the worker">
71 Pass the tool through the worker’s `tools` (go: `ToolsFunc`) factory (see [`EnvironmentWorker`](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#environment-worker)), alongside the built-in toolset:
71 This step uses [`EnvironmentWorker`](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#environment-worker), which only the Python, TypeScript, and Go SDKs have. Pass the tool alongside the built-in toolset through the worker’s `tools` (go: `ToolsFunc`) factory. The samples use `/workspace` as the working directory, which must exist before the worker starts. [Run an always-on worker](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#run-an-always-on-worker) says how to create the directory and what to use on macOS.
7272 
7373 <CodeGroup exclude="shell, csharp, java, php, ruby">
74 <CodeGroupItem language="cURL">
75 A worker is a long-running process, not a single HTTP request. To serve custom tools, use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
76 </CodeGroupItem>
77 
78 <CodeGroupItem language="CLI">
79 The `ant` CLI worker can’t serve custom tools. Use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
80 </CodeGroupItem>
81 
7482 ```python Python
7583 import asyncio
7684 import os
from line 251
243251 List the MCP server’s tools and declare each one as a `custom` tool. The MCP `name`, `description`, and `inputSchema` map one to one onto the custom tool’s fields. If the server paginates its tool list, declare every page; the worker must list the same pages.
244252 
245253 <CodeGroup exclude="shell">
254 <CodeGroupItem language="cURL">
255 Listing an MCP server’s tools and declaring each one needs more logic than a single shell command. Use an MCP SDK and the Anthropic SDK to run it.
256 </CodeGroupItem>
257 
258 <CodeGroupItem language="CLI">
259 Listing an MCP server’s tools and declaring each one needs more logic than a single shell command. Use an MCP SDK and the Anthropic SDK to run it.
260 </CodeGroupItem>
261 
246262 ```python Python
247263 import asyncio
248264 from typing import Any, cast
from line 688
672688 </Step>
673689 
674690 <Step title="Serve the tools from the worker">
675 Connect to the same MCP server at startup, convert its tools with `async_mcp_tool()` (typescript: `mcpTools()`; go: `mcp.NewBetaTools()`), and register them alongside `beta_agent_toolset_20260401()` (typescript: `betaAgentToolset20260401()`; go: `agenttoolset.BetaAgentToolset20260401()`). Keep one MCP session open for the life of the worker.
691 This step uses `EnvironmentWorker`, which only the Python, TypeScript, and Go SDKs have. Connect to the same MCP server at startup. Convert its tools with `async_mcp_tool()` (typescript: `mcpTools()`; go: `mcp.NewBetaTools()`), and register them alongside `beta_agent_toolset_20260401()` (typescript: `betaAgentToolset20260401()`; go: `agenttoolset.BetaAgentToolset20260401()`). Keep one MCP session open for the life of the worker.
676692 
693 The samples use `/workspace` as the working directory, which must exist before the worker starts. [Run an always-on worker](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#run-an-always-on-worker) says how to create the directory and what to use on macOS.
694 
677695 <CodeGroup exclude="shell, csharp, java, php, ruby">
696 <CodeGroupItem language="cURL">
697 A worker is a long-running process, not a single HTTP request. To serve custom tools, use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
698 </CodeGroupItem>
699 
700 <CodeGroupItem language="CLI">
701 The `ant` CLI worker can’t serve custom tools. Use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
702 </CodeGroupItem>
703 
678704 ```python Python
679705 import asyncio
680706 import os
from line 771
745771 await mcpClient.connect(new StreamableHTTPClientTransport(new URL(MCP_SERVER_URL)));
746772 const { tools } = await mcpClient.listTools();
747773 
748 // The MCP SDK's callTool return type still includes a legacy result shape that
749 // mcpTools does not accept; narrow it. Drop this once MCPClientLike widens.
774 // The MCP SDK's callTool return type includes a legacy result shape that
775 // mcpTools does not accept, so narrow it.
750776 const mcpClientForTools: MCPClientLike = {
751777 callTool: (params) => mcpClient.callTool(params) as Promise<MCPCallToolResultLike>
752778 };
from line 896
870896 
871897When the MCP server reports a tool error, the worker posts an error tool result the model can react to. MCP content with no tool result equivalent, such as audio blocks and resource links, also surfaces as an error.
872898 
873Set a timeout on the MCP client for a faster and clearer failure, as the Python worker example does with `read_timeout_seconds`. See [A wrapped MCP tool call hangs](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#a-wrapped-mcp-tool-call-hangs) for what occurs without one.
899Set a timeout on the MCP client for a faster and clearer failure. See [A wrapped MCP tool call hangs](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#a-wrapped-mcp-tool-call-hangs) for what occurs without one.
874900 
875901### Wrap only servers you operate or trust
876902 
Feedback