self-hosted-sandboxes-workers changedmanaged-agents/self-hosted-sandboxes-workers
Nearest release: v2.1.301, published 5 hours before 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+78added
Lines−94removed
From line
40
where the diff opens
First seen
2 Oct 2026
this site's first read of the page
Recorded edits20to this page, all time
The whole hunk
from line 40, old and new numbered
/
from line 40
4040
4141## Run an always-on worker
4242
43Both workers authenticate with the [environment key](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes#run-your-first-session) from the quickstart.
43Start a worker that polls the queue continuously. It authenticates with the [environment key](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes#run-your-first-session) from the quickstart:
4444
45With the `ant` CLI:
45<CodeGroup exclude="shell:cURL, csharp, java, php, ruby">
46 ```bash CLI
47 ant beta:worker poll --workdir /workspace
48 ```
4649
47```bash
48ant beta:worker poll --workdir /workspace
49```
50
51With the SDK, `EnvironmentWorker` does the same work:
52
53<CodeGroup exclude="shell">
5450 ```python Python
5551 import asyncio
5652 import contextlib
from line 101
105101 }).run();
106102 ```
107103
108 ```csharp C#
109 // EnvironmentWorker is not currently available in the C# SDK. Use the ant CLI worker instead.
110 ```
104 <CodeGroupItem language="C#">
105 The C# SDK does not have `EnvironmentWorker`. Run the `ant` CLI worker instead: `ant beta:worker poll --workdir /workspace`.
106 </CodeGroupItem>
111107
112108 ```go Go
113109 package main
from line 141
145141
146142 ```
147143
148 ```java Java
149 // EnvironmentWorker is not currently available in the Java SDK. Use the ant CLI worker instead.
150 ```
144 <CodeGroupItem language="Java">
145 The Java SDK does not have `EnvironmentWorker`. Run the `ant` CLI worker instead: `ant beta:worker poll --workdir /workspace`.
146 </CodeGroupItem>
151147
152 ```php PHP
153 // EnvironmentWorker is not currently available in the PHP SDK. Use the ant CLI worker instead.
154 ```
148 <CodeGroupItem language="PHP">
149 The PHP SDK does not have `EnvironmentWorker`. Run the `ant` CLI worker instead: `ant beta:worker poll --workdir /workspace`.
150 </CodeGroupItem>
155151
156 ```ruby Ruby
157 # EnvironmentWorker is not currently available in the Ruby SDK. Use the ant CLI worker instead.
158 ```
152 <CodeGroupItem language="Ruby">
153 The Ruby SDK does not have `EnvironmentWorker`. Run the `ant` CLI worker instead: `ant beta:worker poll --workdir /workspace`.
154 </CodeGroupItem>
159155</CodeGroup>
160156
161157## Trigger workers from webhooks
from line 172
176172 <Step title="Implement the webhook handler">
177173 Invoke the worker when `session.status_run_started` fires. The handler drains the queue and hands each claimed work item to `handle_item()` (typescript: `handleItem()`; go: `HandleItem()`), which downloads skills, executes tool calls, posts results back, and returns.
178174
179 <CodeGroup exclude="shell">
175 <CodeGroup exclude="shell, csharp, java, php, ruby">
180176 <CodeGroupItem>
181177 To verify webhook signatures, install the webhooks extra: `pip install "anthropic[webhooks]"`.
182178
from line 295
299295 }
300296 ```
301297
302 ```csharp C#
303 // EnvironmentWorker is not currently available in the C# SDK.
304 // To handle work items directly, see the Environments Work endpoints.
305 ```
298 <CodeGroupItem language="C#">
299 The C# SDK does not have `EnvironmentWorker`. To handle work items from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
300 </CodeGroupItem>
306301
307302 ```go Go
308303 package main
from line 410
415410
416411 ```
417412
418 ```java Java
419 // EnvironmentWorker is not currently available in the Java SDK.
420 // To handle work items directly, see the Environments Work endpoints.
421 ```
413 <CodeGroupItem language="Java">
414 The Java SDK does not have `EnvironmentWorker`. To handle work items from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
415 </CodeGroupItem>
422416
423 ```php PHP
424 // EnvironmentWorker is not currently available in the PHP SDK.
425 // To handle work items directly, see the Environments Work endpoints.
426 ```
417 <CodeGroupItem language="PHP">
418 The PHP SDK does not have `EnvironmentWorker`. To handle work items from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
419 </CodeGroupItem>
427420
428 ```ruby Ruby
429 # EnvironmentWorker is not currently available in the Ruby SDK.
430 # To handle work items directly, see the Environments Work endpoints.
431 ```
421 <CodeGroupItem language="Ruby">
422 The Ruby SDK does not have `EnvironmentWorker`. To handle work items from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
423 </CodeGroupItem>
432424 </CodeGroup>
433425
434426 Because the handler claims work itself, it must [forward the work item's secret](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#forward-the-work-items-secret), as the `work_secret` (typescript: `workSecret`; go: `WorkSecret`) argument does here.
from line 497
505497
506498To claim work from your own code instead of `ant beta:worker poll --on-work`, use `work.poller()` (go: `environments.NewWorkPoller()`). It polls the queue and gives you each claimed session, and you launch the sandbox:
507499
508<CodeGroup>
509 ```bash cURL
510 # The work poller is an SDK helper (Python, TypeScript, Go), not a raw
511 # endpoint. From the shell, use `ant beta:worker poll --on-work` instead.
512 ```
500<CodeGroup exclude="shell, csharp, java, php, ruby">
501 <CodeGroupItem language="cURL">
502 Claiming work in a loop and launching a sandbox for each session needs more logic than a single shell command. From the shell, run `ant beta:worker poll --on-work` with a spawn script, as in [Run one sandbox per session](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#run-one-sandbox-per-session).
503 </CodeGroupItem>
513504
514 ```bash CLI
515 # The work poller is an SDK helper (Python, TypeScript, Go), not a raw
516 # endpoint. From the shell, use `ant beta:worker poll --on-work` instead.
517 ```
505 <CodeGroupItem language="CLI">
506 To claim work from the shell and launch a sandbox for each session, run `ant beta:worker poll --on-work` with a spawn script, as in [Run one sandbox per session](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#run-one-sandbox-per-session).
507 </CodeGroupItem>
518508
519509 ```python Python
520510 import asyncio
from line 606
616606 }
617607 ```
618608
619 ```csharp C#
620 // A work-polling helper is not currently available in the C# SDK.
621 // To claim work directly, see the Environments Work endpoints.
622 ```
609 <CodeGroupItem language="C#">
610 The C# SDK does not have a helper that polls for work. To claim work from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
611 </CodeGroupItem>
623612
624613 ```go Go
625614 package main
from line 680
691680 }
692681 ```
693682
694 ```java Java
695 // A work-polling helper is not currently available in the Java SDK.
696 // To claim work directly, see the Environments Work endpoints.
697 ```
683 <CodeGroupItem language="Java">
684 The Java SDK does not have a helper that polls for work. To claim work from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
685 </CodeGroupItem>
698686
699 ```php PHP
700 // A work-polling helper is not currently available in the PHP SDK.
701 // To claim work directly, see the Environments Work endpoints.
702 ```
687 <CodeGroupItem language="PHP">
688 The PHP SDK does not have a helper that polls for work. To claim work from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
689 </CodeGroupItem>
703690
704 ```ruby Ruby
705 # A work-polling helper is not currently available in the Ruby SDK.
706 # To claim work directly, see the Environments Work endpoints.
707 ```
691 <CodeGroupItem language="Ruby">
692 The Ruby SDK does not have a helper that polls for work. To claim work from your own code, call the [Environments Work endpoints](https://platform.claude.com/docs/en/api/beta/environments/work).
693 </CodeGroupItem>
708694</CodeGroup>
709695
710696### Run the SDK worker inside the sandbox
from line 697
711697
712698Replace the `ant beta:worker run` entrypoint with an SDK entrypoint when the sandbox must [serve custom tools](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-custom-tools) or use [non-default memory sync settings](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#configure-sync). The entrypoint constructs `EnvironmentWorker` and calls `handle_item()` (typescript: `handleItem()`; go: `HandleItem()`), which reads the same `ANTHROPIC_*` variables that the spawn script forwards.
713699
714<CodeGroup exclude="shell">
700<CodeGroup exclude="shell, csharp, java, php, ruby">
715701 ```python Python
716702 import asyncio
717703 import contextlib
from line 745
759745 }).handleItem();
760746 ```
761747
762 ```csharp C#
763 // EnvironmentWorker is not currently available in the C# SDK.
764 ```
748 <CodeGroupItem language="C#">
749 The C# SDK does not have `EnvironmentWorker`.
750 </CodeGroupItem>
765751
766752 ```go Go
767753 package main
from line 783
797783
798784 ```
799785
800 ```java Java
801 // EnvironmentWorker is not currently available in the Java SDK.
802 ```
786 <CodeGroupItem language="Java">
787 The Java SDK does not have `EnvironmentWorker`.
788 </CodeGroupItem>
803789
804 ```php PHP
805 // EnvironmentWorker is not currently available in the PHP SDK.
806 ```
790 <CodeGroupItem language="PHP">
791 The PHP SDK does not have `EnvironmentWorker`.
792 </CodeGroupItem>
807793
808 ```ruby Ruby
809 # EnvironmentWorker is not currently available in the Ruby SDK.
810 ```
794 <CodeGroupItem language="Ruby">
795 The Ruby SDK does not have `EnvironmentWorker`.
796 </CodeGroupItem>
811797</CodeGroup>
812798
813799## Stage files for a session
from line 811
825811 -H "anthropic-version: 2023-06-01" \
826812 -H "anthropic-beta: managed-agents-2026-04-01" \
827813 -H "content-type: application/json" \
828 -d @- <<EOF
829 {
830 "agent": "$AGENT_ID",
831 "environment_id": "$ANTHROPIC_ENVIRONMENT_ID",
832 "metadata": {"input_file": "s3://my-bucket/data.csv"}
833 }
834 EOF
814 -d '{
815 "agent": "'"$AGENT_ID"'",
816 "environment_id": "'"$ANTHROPIC_ENVIRONMENT_ID"'",
817 "metadata": {"input_file": "s3://my-bucket/data.csv"}
818 }'
835819 ```
836820
837821 ```bash CLI
No line in this hunk matches that.