self-hosted-sandboxes-memory changedmanaged-agents/self-hosted-sandboxes-memory
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+132added
Lines−44removed
From line
46
where the diff opens
First seen
2 Oct 2026
this site's first read of the page
Recorded edits16to this page, all time
### Read-only stores ### Conflicts
The whole hunk
from line 46, old and new numbered
/
from line 46
4646* **A worker that mounts memory stores:** Use `ant` CLI 1.33.0 or later, or `EnvironmentWorker` from the Python, TypeScript, or Go SDK.
4747* **A POSIX filesystem:** Windows hosts are not supported, because the worker requires `O_NOFOLLOW` when it opens memory files. Anthropic recommends a case-sensitive filesystem, so that memory paths that differ only in case do not collide. macOS volumes are case-insensitive by default, so such paths collide there.
4848* **A writable `/mnt/memory` directory:** See [Prepare the host](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#prepare-the-host). On macOS, see [Prepare a macOS host](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#prepare-a-macos-host).
49* **The work item’s secret:** If your own code launches the worker, [forward the work item’s secret](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#forward-the-work-items-secret) to it.
49* **The work item’s secret:** If your own code launches the worker, [forward the work item’s secret](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-per-session#forward-the-work-items-secret) to it.
5050
5151<Note>
5252 Memory stores are not available for sessions on self-hosted environments on [Claude Models on Google Cloud (Anthropic managed)](https://platform.claude.com/docs/en/build-with-claude/claude-models-on-google-cloud/anthropic-managed) or [Claude Platform on AWS](https://platform.claude.com/docs/en/build-with-claude/claude-platform-on-aws).
from line 62
6262sudo mkdir -p /mnt/memory && sudo chown "$USER" /mnt/memory
6363```
6464
65Do not create the per-store directories yourself. The worker creates each store’s `mount_path` (java, php: `mountPath`; csharp, go: `MountPath`) directory (for example, `/mnt/memory/user-preferences`) when a session starts and removes it when the session ends. If something already exists at that path, the worker refuses to start the session’s work.
65Don’t create any store’s directory yourself. The worker creates each store’s `mount_path` (java, php: `mountPath`; csharp, go: `MountPath`) directory, such as `/mnt/memory/user-preferences`, when it claims a session and removes it when it finishes with that session. If anything already exists at that path, even an empty directory, the worker fails the work item.
6666
67In the [sandbox-per-session pattern](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#run-one-sandbox-per-session), the sandbox image needs a writable `/mnt/memory`. You don’t need to bind-mount the memory directories to the host, because the worker uploads their contents to the store before the sandbox exits.
67In the [sandbox-per-session pattern](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-per-session), the sandbox image needs a writable `/mnt/memory`. You don’t need to bind-mount the memory directories to the host, because the store holds the lasting copy of every memory.
6868
6969### Prepare a macOS host
7070
7171On macOS, the root volume is read-only, so `mkdir` can’t create `/mnt`. Instead, create `/System/Volumes/Data/mnt/memory` on the data volume, which is writable. Then add a line to `/etc/synthetic.conf`, so that macOS creates `/mnt` as a symbolic link to `/System/Volumes/Data/mnt`. These steps need administrator rights.
7272
73Without this setup, the worker can’t create a store’s directory, so it fails the work item. The session then stays idle with no error event. See [Memory stores fail to mount](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#memory-stores-fail-to-mount).
73Without this setup, the worker can’t create a store’s directory, so it fails the work item. The session then stays idle with no error event. See [Memory stores fail to mount or sync](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#memory-stores-fail-to-mount).
7474
7575<Steps>
7676 <Step title="Create the directory on the data volume">
from line 88
8888
8989 * If a line reads `mnt^ISystem/Volumes/Data/mnt$`, this step is already done. Go to the next step.
9090 * If another line starts with `mnt`, stop. Something else on this Mac already defines `/mnt`.
91 * If the last line doesn’t end with `$`, run `echo | sudo tee -a /etc/synthetic.conf` to end it.
92 * If it prints nothing or reports `No such file or directory`, continue. The `printf` command creates the file if it’s missing.
91 * If the last line doesn’t end with `$`, run `echo | sudo tee -a /etc/synthetic.conf` to end it. Then, add the line.
92 * If it prints nothing or reports `No such file or directory`, add the line. The following command creates the file if it’s missing.
93 * Otherwise, add the line.
9394
94 Then add the line, unless one of the first two cases applies. Run this command only once, because each run appends another line.
95 To add the line, run this command. Run it only once, because each run appends another line.
9596
9697 ```bash
9798 printf 'mnt\tSystem/Volumes/Data/mnt\n' | sudo tee -a /etc/synthetic.conf
from line 124
123124
124125### Isolate sessions that share a store
125126
126Two sessions cannot mount the same store on one host at the same time, because both need the same path. If your sessions attach the same store, run one session for each filesystem. Giving each session [its own sandbox](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-workers#run-one-sandbox-per-session) satisfies this rule.
127Two sessions cannot mount the same store on one filesystem at the same time because both need the same path. To run sessions that share a store side by side, give each session its own filesystem. If you use a sandbox for each session, each session gets its own filesystem automatically. See [Run one sandbox per session](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-per-session). One host can run many such sandboxes.
127128
128129## How the worker handles memory
129130
from line 132
131132
1321331. **Downloads each store to its `mount_path` (java, php: `mountPath`; csharp, go: `MountPath`).** This is the same directory under `/mnt/memory/` that cloud sessions use, and the session’s system prompt describes it to the agent. For example, a store named “User Preferences” lands at `/mnt/memory/user-preferences/`.
1331342. **Opens those directories to the file tools.** The agent works on memories with the same file tools it uses in the working directory.
1343. **Reconciles changes after tool calls,** at most once per sync interval (15 seconds by default). Memories that changed in the store are written to disk, and files the agent changed are uploaded to the store.
1354. **Runs a final sync when the session ends.** It flushes any uploads still pending for up to 30 seconds, then removes the directories it created.
1353. **Syncs after tool calls.** The worker syncs after a tool call if the [sync interval](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#sync-interval) (15 seconds by default) has passed since its last sync. Each sync writes changed memories from the store to disk and uploads files that the agent changed.
1364. **Runs a final sync when the session ends or stays idle for the worker’s idle limit.** The final sync can take up to 60 seconds. Changes not uploaded by then are lost. The worker then removes the directories it created.
136137
137The memory store on Anthropic’s side remains the source of truth. [Memory versions](https://platform.claude.com/docs/en/managed-agents/memory#audit-memory-changes), redaction, and viewing or editing memories in the Claude Console work as they do for cloud sessions. The agent’s memory reads and writes appear in the [event stream](https://platform.claude.com/docs/en/managed-agents/events-and-streaming) as ordinary tool events.
138The idle limit is 60 seconds by default. [When the worker finishes with a session](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-reference#when-the-worker-finishes-with-a-session) says what the limit covers and how to change it.
138139
139Because each worker syncs on an interval, a change written in one session becomes visible to another running session only after both have synced. That is typically well under a minute at the default interval. Sessions on cloud sandboxes see each other’s changes almost immediately.
140The agent’s `write` and `edit` tools change only the local copy, and the worker uploads those changes at its next sync. Paths under `/mnt/memory/` outside the store directories are not scratch space. The worker’s file tools refuse to write to them, and anything that a shell command writes there is never synced to a store.
140141
141Each store directory contains a marker file named `.anthropic-memory-store` that ties the directory to its store. Leave it in place: the worker does not sync a directory whose marker is missing or altered.
142[Memory versions](https://platform.claude.com/docs/en/managed-agents/memory#audit-memory-changes), redaction, and viewing or editing memories in the Claude Console work as they do for cloud sessions. The agent’s memory reads and writes appear in the [event stream](https://platform.claude.com/docs/en/managed-agents/events-and-streaming) as ordinary tool events.
142143
144Each store directory contains a marker file named `.anthropic-memory-store` that ties the directory to its store. Leave it in place. If the marker is missing or altered and the directory still holds files, the worker doesn’t sync the directory. It also doesn’t remove the directory when it finishes with the session.
145
143146<Warning>
144 A worker that is killed rather than stopped runs no teardown, so unsynced edits are lost and the store directories stay behind. See [Stop workers gracefully](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#stop-workers-gracefully).
147 If you stop a worker gracefully during a session or [stop the session’s work item](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#stop-a-session-gracefully), the worker still uploads new and changed files. It also removes the store directories. It sends no deletions, so a memory that the agent deleted stays in the store unless an earlier sync already deleted it from the store. A worker that is killed rather than stopped runs no teardown, so unsynced edits are lost and the store directories stay behind. See [Stop workers gracefully](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#stop-workers-gracefully).
145148</Warning>
146149
147150## Configure sync
from line 153
150153
151154### Sync interval
152155
153`memory_sync_interval` (typescript: `memorySyncIntervalMs`; go: `MemorySyncInterval`) sets how often attached stores reconcile with the server while the session runs.
156`memory_sync_interval` (typescript: `memorySyncIntervalMs`; go: `MemorySyncInterval`) sets the shortest time between two syncs while the session runs.
154157
155158| Setting | Value |
156159| ---------------------- | --------------------------------------------------- |
from line 162
159162| Example (10 seconds) | `10` (typescript: `10_000`; go: `10 * time.Second`) |
160163| Disable memory support | `None` (typescript: `null`; go: `-1`) |
161164
165The worker doesn’t sync on a timer. It checks the interval after each call to a tool that runs in your sandbox, such as `bash`, `read`, or a custom tool. The call doesn’t have to touch memory. Without tool calls, nothing syncs until the [final sync](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-memory#how-the-worker-handles-memory). A change in one session reaches another running session only after both have synced, so the wait has no fixed length.
166
162167A shorter interval narrows the window in which another session sees stale memories, at the cost of more memory store requests.
163168
164169Disable memory support only on workers whose sessions attach no memory stores. A disabled worker neither downloads nor syncs stores, so a session with stores attached runs without them even though its system prompt still describes them.
165170
166While memory support is enabled, a work item that arrives without a `secret` (csharp, go: `Secret`) for a session with attached stores fails rather than running without memory. See [Memory stores fail to mount](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#memory-stores-fail-to-mount).
171While memory support is enabled, a work item that arrives without a `secret` (csharp, go: `Secret`) for a session with attached stores fails rather than running without memory. See [Memory stores fail to mount or sync](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#memory-stores-fail-to-mount).
167172
168173### Deletions
169174
from line 180
175180| `"log_only"` (go: `environments.MemorySyncDeletionsLogOnly`) | Runs the same checks but only logs what it would have deleted. Use it to watch what your workers would delete before you trust the enabled mode. |
176181| `"disabled"` (go: `environments.MemorySyncDeletionsDisabled`) | Never deletes from the store. |
177182
178For example, to sync every 10 seconds and only log the deletes the worker would have made:
183For example, to sync at most once every 10 seconds and only log the deletions the worker would have made, use the following sample. The sample uses `/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.
179184
180185<CodeGroup exclude="shell, csharp, java, php, ruby">
186 <CodeGroupItem language="cURL">
187 A worker is a long-running process, not a single HTTP request. To change the sync settings, use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
188 </CodeGroupItem>
189
190 <CodeGroupItem language="CLI">
191 The `ant` CLI worker always uses the default sync settings. To change them, use `EnvironmentWorker` in the Python, TypeScript, or Go SDK.
192 </CodeGroupItem>
193
181194 ```python Python
182 worker = EnvironmentWorker(
183 client,
184 environment_id=environment_id,
185 environment_key=environment_key,
186 workdir="/workspace",
187 memory_sync_interval=10, # seconds
188 memory_sync_deletions="log_only",
189 )
195 import asyncio
196 import contextlib
197 import os
198 import signal
199 from anthropic import AsyncAnthropic
200 from anthropic.lib.environments import EnvironmentWorker
201
202
203 async def main() -> None:
204 environment_key = os.environ["ANTHROPIC_ENVIRONMENT_KEY"]
205 environment_id = os.environ["ANTHROPIC_ENVIRONMENT_ID"]
206 async with AsyncAnthropic(auth_token=environment_key) as client:
207 worker = EnvironmentWorker(
208 client,
209 environment_id=environment_id,
210 environment_key=environment_key,
211 workdir="/workspace",
212 memory_sync_interval=10, # seconds
213 memory_sync_deletions="log_only",
214 )
215 task = asyncio.create_task(worker.run())
216 loop = asyncio.get_running_loop()
217 for signum in (signal.SIGINT, signal.SIGTERM):
218 loop.add_signal_handler(signum, task.cancel)
219 with contextlib.suppress(asyncio.CancelledError):
220 await task
221
222
223 asyncio.run(main())
190224 ```
191225
192226 ```typescript TypeScript
227 import Anthropic from "@anthropic-ai/sdk";
228 import { EnvironmentWorker } from "@anthropic-ai/sdk/helpers/beta/environments";
229
230 const environmentKey = process.env.ANTHROPIC_ENVIRONMENT_KEY!;
231 const environmentId = process.env.ANTHROPIC_ENVIRONMENT_ID!;
232 const client = new Anthropic({ authToken: environmentKey });
233 const controller = new AbortController();
234 process.once("SIGINT", () => controller.abort());
235 process.once("SIGTERM", () => controller.abort());
236
193237 const worker = new EnvironmentWorker({
194238 client,
195239 environmentId,
196240 environmentKey,
197241 workdir: "/workspace",
242 signal: controller.signal,
198243 memorySyncIntervalMs: 10_000,
199244 memorySyncDeletions: "log_only"
200245 });
246 await worker.run();
201247 ```
202248
203249 <CodeGroupItem language="C#">
from line 251
205251 </CodeGroupItem>
206252
207253 ```go Go
208 worker := environments.NewEnvironmentWorker(client, environments.EnvironmentWorkerOptions{
209 EnvironmentID: environmentID,
210 EnvironmentKey: environmentKey,
211 Workdir: "/workspace",
212 MemorySyncInterval: 10 * time.Second,
213 MemorySyncDeletions: environments.MemorySyncDeletionsLogOnly,
214 })
254 package main
255
256 import (
257 "context"
258 "log"
259 "os"
260 "os/signal"
261 "syscall"
262 "time"
263
264 "github.com/anthropics/anthropic-sdk-go/v2"
265 "github.com/anthropics/anthropic-sdk-go/v2/lib/environments"
266 "github.com/anthropics/anthropic-sdk-go/v2/option"
267 )
268
269 func main() {
270 environmentKey := os.Getenv("ANTHROPIC_ENVIRONMENT_KEY")
271 environmentID := os.Getenv("ANTHROPIC_ENVIRONMENT_ID")
272
273 ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
274 defer stop()
275
276 client := anthropic.NewClient(option.WithAuthToken(environmentKey))
277
278 worker := environments.NewEnvironmentWorker(client, environments.EnvironmentWorkerOptions{
279 EnvironmentID: environmentID,
280 EnvironmentKey: environmentKey,
281 Workdir: "/workspace",
282 MemorySyncInterval: 10 * time.Second,
283 MemorySyncDeletions: environments.MemorySyncDeletionsLogOnly,
284 })
285 if err := worker.Run(ctx); err != nil {
286 log.Fatalf("worker: %v", err)
287 }
288 }
215289 ```
216290
217291 <CodeGroupItem language="Java">
from line 303
229303
230304## Read-only stores and conflicts
231305
306### Read-only stores
307
232308For a store attached with `access: "read_only"`, the `write` and `edit` tools refuse to change files inside its directory. The worker never uploads anything from it.
233309
234Changes made through `bash`, or through a custom tool or MCP server you serve from the sandbox, are not blocked locally. They are never synced to the store, and the next remote change to that memory overwrites them. If the local copy itself must stay unchanged during the session:
310Changes made through `bash` or through a custom tool or MCP server you serve from the sandbox are not blocked locally. They never reach the store. A changed file stays changed until one of these things happens:
235311
236* Disable the `bash` tool for that agent, and give it no custom tool that writes to the sandbox’s filesystem.
237* Do not mount the store path read-only. The worker itself must create the directory and write the downloaded memories into it.
312* **That memory gets a new version in the store.** The worker’s next sync overwrites the file with that version.
313* **The worker finishes with the session.** It removes the directory.
238314
239Conflicts resolve in favor of the store. Suppose the agent changes a memory file that also changed in the store since the session last synced it. At the next sync, the worker keeps the store’s version, overwrites the local file with it, and logs a warning. The `write` and `edit` tools themselves succeed and no error reaches the agent. If the agent’s change still applies, it can re-read the file after the sync and make the change again.
315To keep the local copy unchanged too, disable the `bash` tool for that agent. Also, give it no custom tools or MCP servers that write to the sandbox’s filesystem. Don’t mount a read-only volume at the store’s path. The mount puts a directory at that path, and the worker fails the work item if anything already exists there.
240316
317### Conflicts
318
319A conflict is a memory that changed both in the store and in the sandbox since the previous sync. A deletion counts as a change. For a store attached with `access: "read_write"`, the worker resolves the conflict at the next sync:
320
321| In the store | In the sandbox | Result |
322| ------------ | -------------- | ---------------------------------------------------------- |
323| Changed | Changed | The store’s version overwrites the file. |
324| Changed | Deleted | The worker writes the store’s version back to the sandbox. |
325| Deleted | Changed | The worker creates the memory again from the file. |
326
327In the first two rows, the agent’s change or deletion is lost, even though the tool call succeeded. Nothing tells the agent, and the only sign of the loss is a warning in the worker’s log. In the last row, the deletion in the store is undone.
328
241329## Troubleshooting
242330
243See [Memory stores fail to mount](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#memory-stores-fail-to-mount) for the worker’s log messages and their fixes.
331See [Memory stores fail to mount or sync](https://platform.claude.com/docs/en/managed-agents/self-hosted-sandboxes-operations#memory-stores-fail-to-mount) for the worker’s log messages and their fixes.
244332
No line in this hunk matches that.