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-reference changedmanaged-agents/self-hosted-sandboxes-reference

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+199added
Lines−49removed
From line 50 where the diff opens
First seen 2 Oct 2026 this site's first read of the page
Recorded edits16to this page, all time

### When the worker finishes with a session ### Final deliverables

The whole hunk

from line 50, old and new numbered
/
lines
from line 50
5050| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
5151| `--environment-id` | The environment to poll for work. Also reads from `ANTHROPIC_ENVIRONMENT_ID`. |
5252| `--environment-key` | Authenticates the worker with this environment. Also reads from `ANTHROPIC_ENVIRONMENT_KEY`. |
53| `--workdir` | Directory where the worker downloads skills, and where tools read and write files. Defaults to `.` (the current directory). |
53| `--workdir` | Directory where the worker downloads skills and where tools read and write files. Defaults to `.` (the current directory). The directory must exist before the worker starts. |
5454| `--on-work` | Script to call for each claimed work item instead of running tools in process. Receives session details as environment variables and the work item as JSON on standard input. |
5555| `--max-idle` | How long the worker waits while a session is idle before `ant beta:worker run` exits or `ant beta:worker poll` moves on to the next work item. Idle time with a [`requires_action` stop reason](https://platform.claude.com/docs/en/managed-agents/events-and-streaming#respond-when-the-session-goes-idle) does not count. Defaults to `60s`. Set it to `0` to turn off the timeout. With an `--on-work` script, `ant beta:worker poll` ignores this flag. Pass it instead to the `ant beta:worker run` command that your script starts. |
5656| `--log-format` | Log output format. Use `json` for structured log ingestion. Defaults to `text`. |
from line 57
5757 
5858## Environment variables
5959 
60| Variable | Description | Set by |
61| ------------------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
62| `ANTHROPIC_ENVIRONMENT_ID` | The environment whose queue the worker serves. | You, on the worker host. The poller passes it to the `--on-work` script. |
63| `ANTHROPIC_ENVIRONMENT_KEY` | Authenticates the worker to its queue. | You, on the worker host. The poller passes it to the `--on-work` script. |
64| `ANTHROPIC_SESSION_ID` | The session that a claimed work item represents. | The poller, for the `--on-work` script. |
65| `ANTHROPIC_WORK_ID` | The claimed work item. | The poller, for the `--on-work` script. |
66| `ANTHROPIC_WORK_SECRET` | The work item’s secret for its session. | You. The poller does not set it. See [Forward the work item’s secret](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#forward-the-work-items-secret). |
67| `ANTHROPIC_BASE_URL` | Overrides the default API endpoint. Optional. | You, on the worker host. |
68| `ANTHROPIC_WEBHOOK_SIGNING_KEY` | Verifies incoming webhook payloads. | You, on a webhook handler host. |
60| Variable | Description | Set by |
61| ------------------------------- | ------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
62| `ANTHROPIC_ENVIRONMENT_ID` | The environment whose queue the worker serves. | You, on the worker host. The poller passes it to the `--on-work` script. |
63| `ANTHROPIC_ENVIRONMENT_KEY` | Authenticates the worker to its queue. | You, on the worker host. The poller passes it to the `--on-work` script. |
64| `ANTHROPIC_SESSION_ID` | The session that a claimed work item represents. | The poller, for the `--on-work` script. |
65| `ANTHROPIC_WORK_ID` | The claimed work item. | The poller, for the `--on-work` script. |
66| `ANTHROPIC_WORK_SECRET` | The work item’s secret for its session. | You. The poller does not set it. See [Forward the work item’s secret](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-per-session#forward-the-work-items-secret). |
67| `ANTHROPIC_BASE_URL` | Overrides the default API endpoint. Optional. | You, on the worker host. |
68| `ANTHROPIC_WEBHOOK_SIGNING_KEY` | Verifies incoming webhook payloads. | You, on a webhook handler host. |
6969 
7070## Host requirements
7171 
from line 81
8181 
8282## Sandbox filesystem
8383 
84| Path | Contents |
85| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
86| `/workspace` | The system default working directory for running tools and downloading skills. If you use a different working directory, update your agent’s system prompt so Claude can locate the skill files. |
87| `<workdir>/skills/<name>/` | The agent’s downloaded skills. |
88| `/mnt/memory/<store>/` | One directory per attached memory store, at the store’s `mount_path` (java, php: `mountPath`; csharp, go: `MountPath`) (for example, `/mnt/memory/user-preferences/`). The worker creates these directories when it claims the session and removes them when the session ends. |
84| Path | Contents |
85| -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
86| `/workspace` | The working directory in the samples on the self-hosted sandboxes pages. It is not the worker’s default: the worker uses the current directory unless you set `--workdir` or `workdir` (go: `Workdir`). Anthropic’s cloud sandboxes keep skills and repositories in `/workspace`. If you use a different working directory, update your agent’s system prompt so Claude can locate the skill files. |
87| `<workdir>/skills/<name>/` | The agent’s downloaded skills. |
88| `/mnt/memory/<store>/` | A local copy of each attached memory store, one directory per store. The API returns each directory’s full path in the `mount_path` (java, php: `mountPath`; csharp, go: `MountPath`) field of the session’s memory store resource (for example, `/mnt/memory/user-preferences/`). |
8989 
90On self-hosted environments the session’s system prompt omits the `/mnt/session/outputs` instruction used on Anthropic-managed sandboxes. Final deliverables land wherever the agent writes them in your sandbox filesystem, typically under the working directory.
90The worker creates the memory store directories when it claims a session. It removes them when it finishes with that session or when you [stop the worker gracefully](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#stop-workers-gracefully). That removes only the local copies, and the memories stay in the store.
9191 
92Skills can include executables that the agent may run directly. The CLI and SDK workers preserve the executable permissions recorded in the skill bundle when they extract it. If you implement skills download manually, you are responsible for setting executable permissions.
92Skills can include executables that the agent can run directly. The CLI and SDK workers preserve the executable permissions recorded in the skill bundle when they extract it. If you download skills yourself, set their executable permissions yourself.
9393 
94### When the worker finishes with a session
95 
96The worker finishes with a session in any of these cases:
97 
98* The session ends.
99* You [stop the session’s work item](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#stop-a-session-gracefully).
100* The session stays idle for the worker’s idle limit. The session itself stays open. When you then send it a new event, such as a user message, the same worker or another one claims it. That worker downloads the stores again.
101 
102The idle limit is 60 seconds by default. To change it, use [`--max-idle`](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#cli-commands-and-flags) for the `ant` CLI worker or [`max_idle` (typescript: `maxIdleMs`; go: `MaxIdle`)](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#environment-worker) for `EnvironmentWorker`. The [`cma-sandboxes` Helm chart](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-per-session#run-sandboxes-on-kubernetes) starts its workers with a limit of 30 minutes instead. To change that limit, change the chart’s `sandbox.idleTimeout` setting.
103 
104### Final deliverables
105 
106Self-hosted sandboxes have no `/mnt/session/outputs` directory. On Anthropic’s cloud sandboxes, the session’s system prompt tells the agent to copy final deliverables there. On self-hosted environments, the system prompt leaves that instruction out. Final deliverables stay wherever the agent writes them, typically under the working directory, and the worker doesn’t upload them.
107 
108To collect final deliverables in one place, give the full path of a directory in your agent’s system prompt. Choose a directory that the worker’s file tools can write to:
109 
110* **Inside the working directory:** For example, `/workspace/outputs` if the working directory is `/workspace`.
111* **Anywhere else, with an SDK worker only:** Add the directory to `allowed_roots` (typescript: `allowedRoots`; go: `AllowedRoots`). See [AgentToolContext and the agent toolset](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#agent-tool-context-and-the-agent-toolset).
112 
94113## SDK helpers
95114 
96115The Python, TypeScript, and Go SDKs provide three helpers at different levels of control:
from line 117
98117| Helper | What it does | Use it when |
99118| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------ |
100119| [`EnvironmentWorker`](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#environment-worker) | Handles polling, setup, and tool runs end to end. | Most cases. |
101| [`work.poller()` (go: `environments.NewWorkPoller()`)](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#work-poller) | Polls the work queue and gives you each claimed session. | You determine how to handle each session, for example by launching a sandbox rather than running tools in process. |
120| [`work.poller()` (typescript: `new WorkPoller()`; go: `environments.NewWorkPoller()`)](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#work-poller) | Polls the work queue and gives you each claimed session. | You determine how to handle each session, for example by launching a sandbox rather than running tools in process. |
102121| [`client.beta.sessions.events.tool_runner()` (typescript: `client.beta.sessions.events.toolRunner()`; go: `client.Beta.Sessions.Events.NewToolRunner()`)](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#session-tool-runner) | Runs tool calls for a single session, given the session ID and a tool list. | You’ve already claimed the work and only need to run the tools. |
103122 
104123### EnvironmentWorker
105124 
106| Method | Description |
107| ---------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
108| `run()` (go: `Run()`) | Runs indefinitely, picking up sessions as they arrive. |
109| `handle_item()` (typescript: `handleItem()`; go: `HandleItem()`) | Handles a single claimed work item and returns. Pass the work, session, and environment identifiers and the `work_secret` (typescript: `workSecret`; go: `WorkSecret`) explicitly, or let it read the [`ANTHROPIC_*` variables](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#environment-variables). |
125| Method | Description |
126| ---------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
127| `run()` (go: `Run()`) | Runs indefinitely, picking up sessions as they arrive. |
128| `handle_item()` (typescript: `handleItem()`; go: `HandleItem()`) | Handles one work item already claimed by a poller. The poller can be `ant beta:worker poll --on-work` or your own code. The method returns when the worker finishes with the item’s session. You can pass `work_id` (typescript: `workId`; go: `WorkID`), `session_id` (typescript: `sessionId`; go: `SessionID`), `environment_id` (typescript: `environmentId`; go: `EnvironmentID`), and `work_secret` (typescript: `workSecret`; go: `WorkSecret`). For each one that you leave out, the method reads the matching [`ANTHROPIC_*` variable](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#environment-variables). |
110129 
111| Option | Description |
112| -------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
113| `tools` (go: `ToolsFunc`) | A factory that receives the session’s `AgentToolContext` and returns the tool list. Defaults to the standard agent toolset. |
114| `memory_sync_interval` (typescript: `memorySyncIntervalMs`; go: `MemorySyncInterval`) | How often attached memory stores reconcile with the server while the session runs. See [Sync interval](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#sync-interval). |
115| `memory_sync_deletions` (typescript: `memorySyncDeletions`; go: `MemorySyncDeletions`) | Whether files the agent deletes locally are also deleted from the store. See [Deletions](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#deletions). |
130| Option | Description |
131| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
132| `tools` (go: `ToolsFunc`) | A factory that receives the session’s `AgentToolContext` and returns the tool list. Defaults to the standard agent toolset. |
133| `max_idle` (typescript: `maxIdleMs`; go: `MaxIdle`) | How long the worker waits while a session is idle before it finishes with the session. Idle time with a [`requires_action` stop reason](https://platform.claude.com/docs/en/managed-agents/events-and-streaming#respond-when-the-session-goes-idle) does not count. Defaults to 60 seconds. To wait 5 minutes, set it to `300` (typescript: `300_000`; go: `anthropic.Ptr(5 * time.Minute)`). To turn the limit off, set it to `None` (typescript: `0`; go: `new(time.Duration)`). |
134| `memory_sync_interval` (typescript: `memorySyncIntervalMs`; go: `MemorySyncInterval`) | The shortest time between two syncs of the attached memory stores while the session runs. The worker checks the interval after each call to a tool that runs in your sandbox, not on a timer. Defaults to 15 seconds. See [Sync interval](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#sync-interval). |
135| `memory_sync_deletions` (typescript: `memorySyncDeletions`; go: `MemorySyncDeletions`) | Whether files the agent deletes locally are also deleted from the store. See [Deletions](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#deletions). |
116136 
117137`EnvironmentWorker` manages the `AgentToolContext` and the toolset automatically. Pass a `tools` (go: `ToolsFunc`) factory to customize the tool list:
118138 
119139<CodeGroup exclude="shell, csharp, java, php, ruby">
140 <CodeGroupItem language="cURL">
141 A worker is a long-running process, not a single HTTP request. To customize the tool list, use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
142 </CodeGroupItem>
143 
144 <CodeGroupItem language="CLI">
145 The `ant` CLI worker always uses the standard agent toolset. To customize the tool list, use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
146 </CodeGroupItem>
147 
120148 ```python Python
121 EnvironmentWorker(client, ..., tools=lambda env: [beta_bash_tool(env), my_custom_tool])
149 import asyncio
150 import contextlib
151 import os
152 import signal
153 from anthropic import AsyncAnthropic, beta_async_tool
154 from anthropic.lib.environments import EnvironmentWorker
155 from anthropic.lib.tools.agent_toolset import beta_bash_tool
156 
157 
158 @beta_async_tool
159 async def get_order_status(order_id: str) -> str:
160 """Look up an order in the internal fulfillment system by order ID."""
161 return f"Order {order_id}: shipped"
162 
163 
164 async def main() -> None:
165 environment_key = os.environ["ANTHROPIC_ENVIRONMENT_KEY"]
166 environment_id = os.environ["ANTHROPIC_ENVIRONMENT_ID"]
167 async with AsyncAnthropic(auth_token=environment_key) as client:
168 worker = EnvironmentWorker(
169 client,
170 environment_id=environment_id,
171 environment_key=environment_key,
172 # List every tool that the agent can call. The worker answers no other tool.
173 tools=lambda env: [beta_bash_tool(env), get_order_status],
174 )
175 task = asyncio.create_task(worker.run())
176 loop = asyncio.get_running_loop()
177 for signum in (signal.SIGINT, signal.SIGTERM):
178 loop.add_signal_handler(signum, task.cancel)
179 with contextlib.suppress(asyncio.CancelledError):
180 await task
181 
182 
183 asyncio.run(main())
122184 ```
123185 
124186 ```typescript TypeScript
125 new EnvironmentWorker({
187 import Anthropic from "@anthropic-ai/sdk";
188 import { EnvironmentWorker } from "@anthropic-ai/sdk/helpers/beta/environments";
189 import { betaTool } from "@anthropic-ai/sdk/helpers/beta/json-schema";
190 import { betaBashTool } from "@anthropic-ai/sdk/tools/agent-toolset/node";
191 
192 const getOrderStatus = betaTool({
193 name: "get_order_status",
194 description: "Look up an order in the internal fulfillment system by order ID.",
195 inputSchema: {
196 type: "object",
197 properties: { order_id: { type: "string", description: "The order ID" } },
198 required: ["order_id"]
199 },
200 run: async ({ order_id }) => `Order ${order_id}: shipped`
201 });
202 
203 const environmentKey = process.env.ANTHROPIC_ENVIRONMENT_KEY!;
204 const environmentId = process.env.ANTHROPIC_ENVIRONMENT_ID!;
205 const client = new Anthropic({ authToken: environmentKey });
206 const controller = new AbortController();
207 process.once("SIGINT", () => controller.abort());
208 process.once("SIGTERM", () => controller.abort());
209 
210 await new EnvironmentWorker({
126211 client,
127212 environmentId,
128213 environmentKey,
129 tools: (ctx) => [betaBashTool(ctx), myCustomTool]
130 });
214 signal: controller.signal,
215 // List every tool that the agent can call. The worker answers no other tool.
216 tools: (ctx) => [betaBashTool(ctx), getOrderStatus]
217 }).run();
131218 ```
132219 
133220 <CodeGroupItem language="C#">
from line 222
135222 </CodeGroupItem>
136223 
137224 ```go Go
138 worker := environments.NewEnvironmentWorker(client, environments.EnvironmentWorkerOptions{
139 EnvironmentID: environmentID,
140 EnvironmentKey: environmentKey,
141 ToolsFunc: func(env *agenttoolset.AgentToolContext) []anthropic.BetaTool {
142 return []anthropic.BetaTool{agenttoolset.BetaBashTool(env), myCustomTool}
143 },
144 })
225 package main
226 
227 import (
228 "context"
229 "log"
230 "os"
231 "os/signal"
232 "syscall"
233 
234 "github.com/anthropics/anthropic-sdk-go/v2"
235 "github.com/anthropics/anthropic-sdk-go/v2/lib/environments"
236 "github.com/anthropics/anthropic-sdk-go/v2/option"
237 "github.com/anthropics/anthropic-sdk-go/v2/toolrunner"
238 "github.com/anthropics/anthropic-sdk-go/v2/tools/agenttoolset"
239 )
240 
241 type orderStatusInput struct {
242 OrderID string `json:"order_id"`
243 }
244 
245 func main() {
246 environmentKey := os.Getenv("ANTHROPIC_ENVIRONMENT_KEY")
247 environmentID := os.Getenv("ANTHROPIC_ENVIRONMENT_ID")
248 
249 ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
250 defer stop()
251 
252 getOrderStatus := toolrunner.NewBetaTool(
253 "get_order_status",
254 "Look up an order in the internal fulfillment system by order ID.",
255 anthropic.BetaToolInputSchemaParam{
256 Properties: map[string]any{
257 "order_id": map[string]any{"type": "string", "description": "The order ID"},
258 },
259 Required: []string{"order_id"},
260 },
261 func(ctx context.Context, input orderStatusInput) (anthropic.BetaToolResultBlockParamContentUnion, error) {
262 return anthropic.BetaToolResultBlockParamContentUnion{
263 OfText: &anthropic.BetaTextBlockParam{Text: "Order " + input.OrderID + ": shipped"},
264 }, nil
265 },
266 )
267 
268 client := anthropic.NewClient(option.WithAuthToken(environmentKey))
269 
270 worker := environments.NewEnvironmentWorker(client, environments.EnvironmentWorkerOptions{
271 EnvironmentID: environmentID,
272 EnvironmentKey: environmentKey,
273 // List every tool that the agent can call. The worker answers no other tool.
274 ToolsFunc: func(env *agenttoolset.AgentToolContext) []anthropic.BetaTool {
275 return []anthropic.BetaTool{agenttoolset.BetaBashTool(env), getOrderStatus}
276 },
277 })
278 if err := worker.Run(ctx); err != nil {
279 log.Fatalf("worker: %v", err)
280 }
281 }
145282 ```
146283 
147284 <CodeGroupItem language="Java">
from line 296
159296 
160297### Work poller
161298 
162| Option | Description |
163| ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
164| `drain` (go: `Drain`) | Whether to stop polling once the queue is empty rather than waiting for new work. |
165| `block_ms` (typescript: `blockMs`; go: `BlockMs`) | How long each poll waits for work to arrive before returning, in milliseconds. Must be between 1 and 999. The helper polls again automatically. Pass `null` (python: `None`; go: `param.Null[int64]()`) for a non-blocking check. Defaults to a 999ms long-poll. |
166| `reclaim_older_than_ms` (typescript: `reclaimOlderThanMs`; go: `ReclaimOlderThanMs`) | Reclaims work items that were claimed but never acknowledged within this many milliseconds. |
167| `auto_stop` (typescript: `autoStop`; go: `AutoStop`) | Whether to post a stop signal for each work item once your loop body finishes with it. Set it to `false` (python: `False`; go: `param.NewOpt(false)`) when whatever runs the work item posts the stop itself. `handle_item()` (typescript: `handleItem()`; go: `HandleItem()`) does, and so does a sandbox you launch that owns the stop call. |
299| Option | Description |
300| ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
301| `drain` (go: `Drain`) | Whether to stop polling once the queue is empty rather than waiting for new work. |
302| `block_ms` (typescript: `blockMs`; go: `BlockMs`) | How long each poll waits for work to arrive before returning, in milliseconds. Must be between 1 and 999. The helper polls again automatically. Pass `null` (python: `None`; go: `param.Null[int64]()`) for a non-blocking check. Defaults to a 999ms long-poll. |
303| `reclaim_older_than_ms` (typescript: `reclaimOlderThanMs`; go: `ReclaimOlderThanMs`) | Reclaims work items that were claimed but never acknowledged within this many milliseconds. |
304| `auto_stop` (typescript: `autoStop`; go: `AutoStop`) | Whether the poller posts a stop signal for each work item once your loop body finishes with it. Defaults to `true` (python: `True`). Set it to `false` (python: `False`; go: `param.NewOpt(false)`) in the two cases that follow this table. |
168305 
169For a complete example, see [Launch sandboxes from the SDK poller](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#launch-sandboxes-from-the-sdk-poller).
306Set `auto_stop` (typescript: `autoStop`; go: `AutoStop`) to `false` (python: `False`; go: `param.NewOpt(false)`) in two cases:
170307 
3081. Your loop calls `handle_item()` (typescript: `handleItem()`; go: `HandleItem()`), which posts the stop itself.
3092. Your loop launches a sandbox for the item and moves on. The worker in that sandbox must post the stop when the session’s work ends, as `ant beta:worker run` and `handle_item()` (typescript: `handleItem()`; go: `HandleItem()`) do.
310 
311For a complete example, see [Launch sandboxes from the SDK poller](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-per-session#launch-sandboxes-from-the-sdk-poller).
312 
171313### Session tool runner
172314 
173315`client.beta.sessions.events.tool_runner()` (typescript: `client.beta.sessions.events.toolRunner()`; go: `client.Beta.Sessions.Events.NewToolRunner()`) takes a tool list as `tools` (go: `Tools`). To build that list, set up `AgentToolContext` yourself and call `beta_agent_toolset_20260401(env)` (typescript: `betaAgentToolset20260401(ctx)`; go: `agenttoolset.BetaAgentToolset20260401(env)`):
174316 
175317<CodeGroup exclude="shell, csharp, java, php, ruby">
318 <CodeGroupItem language="cURL">
319 `AgentToolContext` is a helper in the Python, TypeScript, and Go SDKs. cURL has no equivalent. Use one of those SDKs.
320 </CodeGroupItem>
321 
322 <CodeGroupItem language="CLI">
323 `AgentToolContext` is a helper in the Python, TypeScript, and Go SDKs. The `ant` CLI has no equivalent. Use one of those SDKs.
324 </CodeGroupItem>
325 
176326 ```python Python
177327 from anthropic.lib.tools.agent_toolset import (
178328 AgentToolContext,
Feedback