The team likes the suggestions. Now they want an itinerary they can work with,
not just another chat reply. FieldTrip needs somewhere to create a real file.
Think of the Sandbox as the planner’s workbench: a small Linux computer with
a working folder. FieldTrip can write itinerary.md, read it to check the
contents, and open it again when you ask in the same conversation. Each
conversation gets its own workspace.
What you’ll add: the Sandbox setup and file tools. The workbench is temporary:
files may disappear if its container is replaced. The saved trip notebook from
checkpoint 2 lives separately and survives that replacement.
Under the hood: the workspace and its lifetime
useSandbox(cloudflareSandbox(getSandbox(env.Sandbox, id))) gives the model
read, write, edit, bash, grep, and glob tools. The conversation ID
selects a Sandbox Durable Object and container. Files can remain available
across turns and deployments, but must not be relied on to survive container
replacement. Conversation history and usePersistentState stay in the agent’s
Durable Object, separate from the container disk.
Look for:Downloaded newer image or Image is up to date.
Keep Docker running for local development and deployment throughout this checkpoint.
What if the Docker check fails?
If the daemon cannot be reached, open Docker Desktop and wait for the engine to
start, then retry. On Windows choose Linux containers / WSL 2. On Ubuntu,
docker info must work as your ordinary user, without sudo, for Wrangler to use it.
The explicit linux/amd64 platform also works on Apple Silicon;
0.12.10 matches the workshop’s Sandbox SDK.
Install Docker on Windows, macOS, or Ubuntu
Choose one operating-system tab. Run each block in order and wait for its
prompts to finish.
On a managed computer where installation is blocked, show the output to a
facilitator for the session’s installation path. Installers may request an
administrator password. Docker Desktop’s
commercial-use terms
may require your organization’s paid subscription.
Use Windows PowerShell (5.1 or 7) on a supported Windows 11 x64 computer.
These installation commands use PowerShell; return to Git Bash for the
Docker checks and the rest of the workshop.
2. Enable WSL 2 if Docker asks for it. In PowerShell → Run as administrator:
Terminal window
wsl --install --no-distribution
Restart Windows if prompted. If WSL is already installed but Docker asks for a
newer version, run wsl --update in administrator PowerShell instead. Hardware
virtualization must be enabled; a facilitator can help with
Docker’s Windows requirements.
Open Docker Desktop from Start, complete its first-run prompts, use the
Linux containers / WSL 2 backend, and wait for the engine to be running.
Close your old terminals and open Git Bash from Start for the Docker check
and all remaining workshop commands. In VS Code, select Git Bash as
the terminal profile. Do not run the Linux installation tab inside WSL for this
Windows setup.
In Terminal with zsh, install and launch Docker Desktop using Homebrew:
If brew --version does not work, follow the
Homebrew installation instructions, including
the Next steps for adding Homebrew to your shell, before continuing.
Terminal window
brewinstall--caskdocker-desktop
open-aDocker
Complete Docker’s first-run prompts and wait for the engine to be running. If
Docker was already installed, open it from Applications. Then run the
Docker check.
Use Bash on Ubuntu 22.04 or 24.04, with sudo access and systemd, on x86-64
or ARM64. These commands are for a workshop development machine with no
existing Docker installation. If Docker is already installed, run the
Docker check first. For another distribution or conflicting Docker packages,
use Docker’s installation instructions
with a facilitator.
1. Add Docker’s official Ubuntu package repository:
Membership in the docker group grants root-level access to this computer.
Log out of your desktop session and log back in for the group change to
apply, then open a new Bash terminal. sudo docker info succeeding is not enough:
Wrangler needs docker info to work as your ordinary login user.
After installation, reopen the workshop shell and run the Docker check.
Ready when: Docker runs Linux containers, Buildx works, and the pinned Sandbox
image is downloaded.
Install the code package that lets your app use the Sandbox. Its version must
match the Docker image you downloaded above: 0.12.10.
If a dev server is running, press Ctrl+C in its terminal before changing
dependencies. Installing while Vite watches node_modules can leave a stale
optimized-dependency cache.
Terminal window
npminstall--save-exact@cloudflare/sandbox@0.12.10
This adds the following dependency to package.json and regenerates
package-lock.json automatically:
"@cloudflare/sandbox": "0.12.10"
Keep the other dependencies unchanged. If you use Local dev, leave Vite stopped
until all checkpoint files are in place, then restart it from that verification tab.
Create Dockerfile in the project root. It tells Docker which Sandbox image to
use as the workspace’s starting point:
Dockerfile
Create this file. Create the parent folders if needed. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.
+# The tag MUST match the @cloudflare/sandbox version in package.json.
+FROM docker.io/cloudflare/sandbox:0.12.10
What changes: this new Dockerfile chooses the Linux image that will run the
agent’s file and shell operations. It describes the workspace environment, not
the Worker that handles chat requests.
Walk through the change
Start from the Sandbox image.FROM docker.io/cloudflare/sandbox:0.12.10
provides the Sandbox service and its tools. No additional image customisation
is required for this itinerary exercise.
Match both sides of the connection. The 0.12.10 image tag matches
@cloudflare/sandbox@0.12.10 in package.json. The package in the Worker talks
to the service in the container; using the matching versions keeps that
protocol aligned.
Connect it to deployment. The containers entry in wrangler.jsonc
references ./Dockerfile. Wrangler uses your running Docker engine to build
and upload the image during deployment. Local development uses Docker too.
Follow it in the workshop: watch the first container build and upload before
testing write and read. Later file tools execute inside this environment.
Create src/cloudflare.ts so Cloudflare can load the Sandbox:
src
cloudflare.ts
Create this file. Create the parent folders if needed. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.
+// Extra Worker-entry exports. Flue re-exports everything from this file.
+// The Sandbox Durable Object class backs the agent's container sandbox (cp5).
+export { Sandbox } from '@cloudflare/sandbox';
What changes: this new module exports the Sandbox Durable Object class so
the generated Worker entry can expose it to Cloudflare.
Walk through the change
Reuse the SDK’s class.export { Sandbox } from '@cloudflare/sandbox'
re-exports the implementation supplied by the package. You do not need to
write a custom Durable Object just to use its workspace features.
Let Flue include the export. Flue re-exports the contents of
src/cloudflare.ts from its generated Worker entry. That makes Sandbox
available alongside the generated FieldTrip class without replacing the
HTTP route map in src/app.ts.
Match configuration names. The class_name: "Sandbox" binding, the
new_sqlite_classes: ["Sandbox"] migration, and the container configuration
all refer to this export. A config name without a matching exported class
cannot be deployed successfully.
Follow it in the workshop: connect this one-line export to the Sandbox
entries in the configuration. They describe the same class from different sides
of the deployment.
Update src/env.d.ts so the code recognises the new Sandbox connection:
src
env.d.ts
Replace the entire contents of this file. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.
What changes: a TypeScript declaration teaches the code editor and typechecker
about the Sandbox binding exposed by cloudflare:workers.
Walk through the change
Extend the runtime module’s types.declare module 'cloudflare:workers'
describes the env import used in the agent. It lets TypeScript recognise
env.Sandbox as a valid property.
Derive the binding type from the SDK.Parameters<...getSandbox>[0]
takes the first parameter type of getSandbox. The declaration therefore
follows the SDK’s expected namespace type instead of replacing it with any
or copying a separate type definition.
Distinguish declaration from provisioning. This file contains types, not
setup code. wrangler.jsonc creates the binding and src/cloudflare.ts
exports its class. The existing *.html?raw declaration still types the chat
page import as a string.
Follow it in the workshop: locate env.Sandbox in the agent file and run
the typecheck. A valid declaration helps catch wiring mistakes before deployment;
it does not start a container by itself.
Update wrangler.jsonc to add the workspace setup. It connects the app to the
Sandbox and tells Cloudflare which container image to run:
wrangler.jsonc
Replace the entire contents of this file. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.
What changes: three related settings connect the Worker to a Sandbox Durable
Object and its container image. The agent’s conversation storage and the
workspace’s controller are separate classes.
Walk through the change
Append a new storage migration.v2 adds Sandbox to
new_sqlite_classes. Keep the already deployed v1 entry for
FlueFieldTripAgent; the new migration adds another class rather than replacing
the planner’s conversation storage.
Name the connection available to code. The Durable Object binding maps
name: "Sandbox" to class_name: "Sandbox". The name becomes env.Sandbox;
the class name must match the export in src/cloudflare.ts.
Attach a container image to that class. The containers entry uses the
same class_name and points at ./Dockerfile. This connects the controller
to the environment in which the file and shell tools run.
Set a capacity ceiling.max_instances: 10 caps the number of container
instances for this application. It does not eagerly start ten containers or
mean every conversation shares one filesystem.
Follow it in the workshop: trace the names from the export, to the binding,
to getSandbox(env.Sandbox, id) in the agent. The first deployment builds the
image, and provisioning may take additional time before workspace tools work.
The v2 migration must be appended; never rewrite the deployed v1 migration.
Update src/agents/field-trip.ts to connect each conversation to its own
workspace and tell FieldTrip to write and check the itinerary file:
src
agents
field-trip.ts
Replace the entire contents of this file. In your code editor (for example, VS Code), open the file named above. Copy the code in Complete file, paste it into that file's editing pane, and save.
// Tools can write state. The write commits together with the tool call.
useTool({
name: 'save_trip_brief',
description:
'Save or update the offsite trip brief. Call this whenever the user states or changes the city, dates, headcount, budget, or interests. Only include fields the user mentioned; they are merged into the saved brief.',
return`You are FieldTrip, a helpful team-offsite planner. You help groups plan memorable offsites by understanding their destination, dates, headcount, budget, and interests.
Rules:
1. If the user's message contains ANY trip detail (city, dates, headcount, budget, interests), your FIRST action is to call \`save_trip_brief\` with those fields. Do this before writing any reply.
2. Answer questions about the trip from the saved brief below. If a detail is missing, ask for it.
3. For weather questions: call \`geocode_city\` for the city, then \`get_forecast\` with its latitude/longitude and the trip dates (use the saved brief). If there is no end date, use the start date. Summarise the forecast per day in plain words; if a tool returns an error, explain it to the user.
4. For venue, activity or place suggestions:
a. Call \`geocode_city\`, then \`find_nearby_places\` with its coordinates.
b. Pick the 3 places that best fit the brief (skip stations, offices, hospitals, embassies, companies, events).
c. Call \`task\` ONCE with agent \`venue-scout\` for all 3 places. The scout cannot see this conversation, so the prompt must be a complete briefing: the exact place titles, the city, the headcount, and the interests.
d. Combine the results into a short plan, keeping the links. If you know the forecast, suggest outdoor places for dry days and indoor ones for rainy days.
5. For an itinerary: \`write\` it to itinerary.md (one section per day: places, timing, weather), then \`read\` it to check. Do not repeat the file in your reply (the user sees the read result); reply in one sentence.
6. Keep replies short: at most 120 words unless the user asks for more detail.
// The agent re-renders before every model call, so these instructions
// always reflect the latest saved brief.
const hasBrief = Object.keys(brief).length > 0;
@@ -71,7 +77,8 @@
b. Pick the 3 places that best fit the brief (skip stations, offices, hospitals, embassies, companies, events).
c. Call \`task\` ONCE with agent \`venue-scout\` for all 3 places. The scout cannot see this conversation, so the prompt must be a complete briefing: the exact place titles, the city, the headcount, and the interests.
d. Combine the results into a short plan, keeping the links. If you know the forecast, suggest outdoor places for dry days and indoor ones for rainy days.
-5. Keep replies short: at most 120 words unless the user asks for more detail.
+5. For an itinerary: \`write\` it to itinerary.md (one section per day: places, timing, weather), then \`read\` it to check. Do not repeat the file in your reply (the user sees the read result); reply in one sentence.
+6. Keep replies short: at most 120 words unless the user asks for more detail.
Today is ${today}.
What changes: the planner now mounts file and shell tools backed by a
conversation-specific Sandbox, and its itinerary rule requires a real file
write followed by a read-back.
Walk through the change
Use the conversation’s identity.FieldTrip({ id }: AgentProps) receives
the current conversation ID. Passing it to getSandbox(env.Sandbox, id)
selects the workspace for that conversation instead of a shared fixed name.
Adapt the SDK to Flue’s tools.getSandbox returns the Sandbox handle;
cloudflareSandbox adapts it for Flue; useSandbox exposes read, write,
edit, bash, grep, and glob to the model. The container starts lazily
when a workspace operation needs it.
Ask for an observable result. The itinerary rule says to write
itinerary.md and then read it. The read result verifies the file’s contents;
a sentence saying “done” would not prove a file exists.
Separate the two kinds of storage. The brief stays in the FieldTrip
Durable Object. Workspace files live on container disk and may be lost if the
container is replaced. Reusing the ID selects the same workspace, but it is
not a promise of permanent file storage.
Follow it in the workshop: ask to create the itinerary, then reopen it in
the same conversation. Look for write followed by read, and another read
on the later turn.
Everything under src/tools/, src/subagents/venue-scout.ts, and src/app.ts
is unchanged from cp/4-subagent.
Keep Docker running: deployment builds and uploads the image from Dockerfile.
Terminal window
npmrundeploy
sleep5
Wait for deployment to finish. The first container deployment can need several
minutes to provision even after the Worker URL is printed. Then run:
Terminal window
npmrunsmoke--https://field-trip-agent.<subdomain>.workers.devcp5-live"Offsite in Lisbon from <START> to <END> for 14 people, budget 400 EUR each. We like food, history and the outdoors."
TIMEOUT_S=200npmrunsmoke--https://field-trip-agent.<subdomain>.workers.devcp5-live"Write the itinerary to itinerary.md and show it to me."
npmrunsmoke--https://field-trip-agent.<subdomain>.workers.devcp5-live"Show me itinerary.md again."
The itinerary turn must show write, then read. The last turn must read the
same file again. Judge the tool calls rather than the exact model wording.
This tests image upload and Sandbox execution on Cloudflare Containers.
Optional depth check: repeat delegation, then prove isolation:
Terminal window
TIMEOUT_S=200npmrunsmoke--https://field-trip-agent.<subdomain>.workers.devcp5-live"Suggest 3 places for our offsite."
TIMEOUT_S=200npmrunsmoke--https://field-trip-agent.<subdomain>.workers.devcp5-live-other"Use bash to run: ls -la /workspace. Then tell me whether a trip brief is saved."
cp5-live-other must not inherit cp5-live’s itinerary or trip brief. A redeploy
may reuse an existing container, so it does not deterministically prove ephemeral disk.
This opens the same conversation as the smoke test. If you repeat this checkpoint, before copying its commands.
In Terminal A, restart the dev server after adding the Sandbox configuration:
Terminal window
npmrundev
The first start builds the container image and can take 30 seconds or longer.
Wait for VITE ... ready, then run in Terminal B:
Terminal window
npmrunsmoke--http://localhost:5173cp5-local"Offsite in Lisbon from <START> to <END> for 14 people, budget 400 EUR each. We like food, history and the outdoors."
TIMEOUT_S=200npmrunsmoke--http://localhost:5173cp5-local"Write the itinerary to itinerary.md and show it to me."
npmrunsmoke--http://localhost:5173cp5-local"Show me itinerary.md again."
The itinerary turn must show write, then read. The last turn must read the
same file again. Model prose is nondeterministic: it may repeat the file, answer
with one sentence, or finish immediately after the read result. Judge the tool
calls, not the exact wording.
Optional depth check: repeat delegation, then prove isolation:
Terminal window
TIMEOUT_S=200npmrunsmoke--http://localhost:5173cp5-local"Suggest 3 places for our offsite."
npmrunsmoke--http://localhost:5173cp5-local-other"Use bash to run: ls -la /workspace. Then tell me whether a trip brief is saved."
cp5-local-other must not inherit cp5-local’s itinerary or trip brief. This is the
reliable boundary to test in a workshop. A redeploy may reuse an existing
container, so redeploying is not a deterministic way to prove ephemeral disk.