Sandboxes now support real-time filesystem watching via sandbox.watch(). The method returns a Server-Sent Events stream backed by native inotify, so your Worker receives create, modify, delete, and move events as they happen inside the container.
sandbox.watch(path, options)
Pass a directory path and optional filters. The returned stream is a standard ReadableStream you can proxy directly to a browser client or consume server-side.
JavaScript
// Stream events to a browser clientconst stream = await sandbox.watch("/workspace/src", {recursive: true,include: ["*.ts", "*.js"],});return new Response(stream, {headers: { "Content-Type": "text/event-stream" },});TypeScript
// Stream events to a browser clientconst stream = await sandbox.watch("/workspace/src", {recursive: true,include: ["*.ts", "*.js"],});return new Response(stream, {headers: { "Content-Type": "text/event-stream" },});
Server-side consumption with parseSSEStream
Use parseSSEStream to iterate over events inside a Worker without forwarding them to a client.
JavaScript
import { parseSSEStream } from "@cloudflare/sandbox";const stream = await sandbox.watch("/workspace/src", { recursive: true });for await (const event of parseSSEStream(stream)) {console.log(event.type, event.path);}TypeScript
import { parseSSEStream } from "@cloudflare/sandbox";import type { FileWatchSSEEvent } from "@cloudflare/sandbox";const stream = await sandbox.watch("/workspace/src", { recursive: true });for await (const event of parseSSEStream<FileWatchSSEEvent>(stream)) {console.log(event.type, event.path);}
Each event includes a type field (create, modify, delete, or move) and the affected path. Move events also include a from field with the original path.
Options
| Option | Type | Description |
|---|---|---|
recursive | boolean | Watch subdirectories. Defaults to false. |
include | string[] | Glob patterns to filter events. Omit to receive all events. |
Upgrade
To update to the latest version:
npm i @cloudflare/sandbox@latestFor full API details, refer to the Sandbox file watching reference.
Source: Cloudflare
Latest Posts
- Microsoft Dataverse – Restore deleted Dataverse records within a specified timeframe [MC1262302]
![Microsoft Dataverse - Restore deleted Dataverse records within a specified timeframe [MC1262302] 2 pexels steve 12891176](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) User reported security signals in Teams admin center [MC1227625]
![(Updated) User reported security signals in Teams admin center [MC1227625] 3 pexels droosmo 2958565](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) Microsoft Teams: Automatically set work location by connecting to a Wi-Fi network [MC1081568]
![(Updated) Microsoft Teams: Automatically set work location by connecting to a Wi-Fi network [MC1081568] 4 pexels felixmittermeier 957090](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)
- (Updated) Transitioning Teams Android Device Management from Teams admin Center to the Teams Rooms Pro Management portal [MC1227622]
![(Updated) Transitioning Teams Android Device Management from Teams admin Center to the Teams Rooms Pro Management portal [MC1227622] 5 teddy bear 1835598 1920](data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==)

![Microsoft Dataverse - Restore deleted Dataverse records within a specified timeframe [MC1262302] 2 pexels steve 12891176](https://mwpro.co.uk/wp-content/uploads/2025/06/pexels-steve-12891176-150x150.webp)
![(Updated) User reported security signals in Teams admin center [MC1227625] 3 pexels droosmo 2958565](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-droosmo-2958565-150x150.webp)
![(Updated) Microsoft Teams: Automatically set work location by connecting to a Wi-Fi network [MC1081568] 4 pexels felixmittermeier 957090](https://mwpro.co.uk/wp-content/uploads/2024/08/pexels-felixmittermeier-957090-150x150.webp)
![(Updated) Transitioning Teams Android Device Management from Teams admin Center to the Teams Rooms Pro Management portal [MC1227622] 5 teddy bear 1835598 1920](https://mwpro.co.uk/wp-content/uploads/2025/06/teddy-bear-1835598_1920-150x150.webp)
