Prepare the agent’s environment
Install project dependencies before an agent starts and reuse download caches.
Use this guide when a task fails because project tools or dependencies are missing. Keep the agent image for installed tools and use preparation hooks for the repository’s dependencies. A download cache can speed installation up; it does not replace installation.
Install dependencies before agent work
Section titled “Install dependencies before agent work”Use a sandboxReady hook to install project dependencies before the agent starts. The command runs in the prepared sandbox, so the agent can use the installed packages during its task.
npm ci runs inside the sandbox, in the repository root. The agent starts with node_modules installed. createSandbox() and openWorkspace() accept the same hooks; speculate() takes them under sandbox.
Choose where each hook runs
Section titled “Choose where each hook runs”API reference: LifecycleHooks.
hostReady and sandboxReady run at the same time. Install dependencies in sandboxReady: they then match the sandbox’s operating system and architecture.
Each entry is a command: executable, arguments, and optionally directory, variables and deadlineMs. These hooks prepare the environment; to intercept the agent’s tool calls, see Permissions and hooks.
Prepare once for several turns
Section titled “Prepare once for several turns”A sandbox runs unconditional hooks once, when it is allocated. sandbox.dispatch(), sandbox.resume() and sandbox.command() reuse the prepared environment. Each top-level dispatch() allocates a fresh sandbox and runs them again.
A workspace from openWorkspace() runs workspaceReady once when it opens. It runs hostReady and sandboxReady for each sandbox it creates, unless that sandbox passes its own hooks, which replace the workspace’s.
For this step, follow Reuse dependency downloads.
Limits
Section titled “Limits”- Local and Firecracker providers have no
caches:sandboxReadydownloads everything on each allocation. - Each hook command stops after 10 minutes unless you set
deadlineMs. - At allocation, a command that exits with a nonzero status rejects with an
OutpostErrorof codeprocess, stops the other preparation commands and releases the sandbox. See Errors. - Commands run without a shell. Call
sh -cfor pipes and&&. - Cache names start with a lowercase letter and hold at most 48 lowercase letters, digits or hyphens. Explicit
volumescannot overlap/outpost/cache. - Every sandbox that mounts a cache can change its content, and later sandboxes read it. Keep credentials out of caches (Security).
API: dispatch · createSandbox · openWorkspace · LifecycleHooks · Command · ContainerOptions · DependencyCache.
Top-level dispatch({ passes }) allocates once per pass, so unconditional preparation runs for every pass. Passes on an already open sandbox reuse its preparation.

