Skip to content
Français

Reuse dependency downloads

Speed up repeated runs while keeping installation explicit.

Start from Prepare the agent’s environment and its configuration. Speed up repeated runs while keeping installation explicit.

Keep secrets out of caches: one sandbox can change what later sandboxes read. A cache retains downloads; npm ci must still install dependencies. Local and Firecracker do not expose caches.

Add when: changed(["package-lock.json"]) to check file contents before each sandbox.command(), dispatch() (including resume and fork) or attach(). The first preparation always runs the hook; later operations skip it until a watched file changes.

import { changed, createSandbox } from "@elie-laloum/outpost/core";
import { repository, sandboxProvider } from "./outpost.config.ts";

await using sandbox = await createSandbox({
  repository,
  sandboxProvider,
  hooks: {
    sandboxReady: [
      {
        executable: "npm",
        arguments: ["ci"],
        when: changed(["package-lock.json"]),
      },
    ],
  },
});
await sandbox.command({ executable: "npm", arguments: ["test"] });

Outpost hashes the watched files inside the hook’s execution environment, relative to its directory or the workspace root. List exact file paths, without glob patterns, absolute paths or ... Content changes, creation and deletion count; timestamps do not. Missing files have a stable fingerprint; an unreadable file fails preparation. Node.js must be available in that environment.

Each hook keeps its own fingerprint in memory for this sandbox, recorded only after success. A failed, timed-out or cancelled preparation blocks the requested operation and is retried on the next call; the sandbox remains open. A new sandbox always prepares again. Only declared files are watched: deleting node_modules alone does not trigger installation. A hook that changes a watched file runs again on the next operation.

hostReady supports the same condition on host files. workspaceReady is evaluated once at workspace opening. Ordering stays the same: host commands run sequentially, sandbox commands run concurrently, and both groups overlap. No hook runs between passes of one dispatch; file changes made during an operation are checked at the next operation.

API: changed · LifecycleCommand · ChangedCondition. The repository’s examples/60-incremental-preparation/index.ts demonstrates npm ci without account credentials or network access.

Docker and Podman providers accept caches: named volumes that survive the container. Point your package manager at the mounted directory.

import { createDockerSandboxProvider } from "@elie-laloum/outpost/providers/docker";

export const sandboxProvider = createDockerSandboxProvider({
  image: "outpost-codex:dev",
  caches: [{ name: "npm", key: "node24" }],
  variables: { npm_config_cache: "/outpost/cache/npm" },
});

Each cache is mounted at /outpost/cache/<name>, owned by the container user. The next sandbox with the same key finds the downloads there. Change key when cached content stops being compatible, for example after a runtime upgrade.

Package managerVariable
npmnpm_config_cache
YarnYARN_CACHE_FOLDER
pipPIP_CACHE_DIR
Go modulesGOMODCACHE

Keep the install command in sandboxReady. The cache saves downloads, not the installed project: the package manager still checks the lockfile and fills node_modules.

Vercel and Daytona accept the same cache name and compatibility key, plus a transport for each cache. This example uses a private S3 prefix; install @aws-sdk/client-s3 alongside Outpost. The caller owns the S3 client and must destroy it after closing all sandboxes.

import { S3Client } from "@aws-sdk/client-s3";
import { createS3Transport } from "@elie-laloum/outpost/transports/s3";
import { createVercelSandboxProvider } from "@elie-laloum/outpost/providers/vercel";

export const client = new S3Client({});
const s3 = createS3Transport({
  client,
  bucket: "my-private-bucket",
  prefix: "outpost-downloads",
});
export const sandboxProvider = createVercelSandboxProvider({
  create: { runtime: "node24" },
  caches: [{ name: "npm", key: "app-node24", transport: s3 }],
  variables: { npm_config_cache: "/outpost/cache/npm" },
});

Restoration finishes before sandboxReady; keep npm ci or pip install in that hook. Downloads are archived when the sandbox closes, after all warm commands and turns, including normal cleanup after a failed or cancelled run. Storage credentials stay on the host. createLocalTransport() also works when successive cloud runs share one host.

The identity uses the same hash recipe as container caches: canonical host repository, execution image, UID/GID, name and key. In the cloud, the image component includes the provider and its configured runtime/image/source (Vercel) or image/snapshot (Daytona). Different providers and host checkout paths do not share archives. Pin images and change key when a mutable image or package-manager version changes compatibility.

A cloud sandbox receives its own snapshot. The first run to publish against the revision it restored wins; a stale concurrent publisher keeps the newer snapshot and discards its update. The cache is not a merged filesystem. Missing caches start empty. Other transport, archive or transfer failures fail acquisition or closing; closing still attempts sandbox disposal and reports both failures if necessary.

Archives preserve files, binary bytes, permissions and symlinks, including dependency checkouts containing .git; empty directories are recreated by the package manager. The existing archive limits apply: 1 GiB of payload, 100,000 files and a 16 MiB manifest. Restoration and each cache save have a 60-second deadline. Commands create /outpost/cache/<name> and assign it to the sandbox user; non-root images must permit elevated setup.

Objects live under dependency-caches/ in the transport. Immutable snapshots, including superseded or unpublished snapshots, remain until you remove them. Remove a cache’s entire prefix only after stopping every reader and writer; deleting chunks used by an active restoration makes it fail. No snapshot pruning is automatic. A killed runner or an expired cloud sandbox may leave the latest downloads unsaved. Deterministic SDK fixtures cover the behavior; live Vercel, Daytona and S3 validation remains pending.

API: CloudDependencyCache · VercelOptions · DaytonaOptions · Transport.

A volume is shared by sandboxes with the same repository, image, container user, cache name and key. Closing a sandbox and outpost image remove keep it. Outpost labels its volumes io.outpost.cache=true:

docker volume ls --filter label=io.outpost.cache=true
docker volume rm $(docker volume ls -q --filter label=io.outpost.cache=true)

Podman accepts the same commands with podman.

Cloud cache transfers use the provider file APIs and may make one request per file. Each cache can set timeoutMs (60 seconds by default); restoration shares the largest declared timeout, while each save gets its own deadline. Increase this limit for many small files or a slow service. Cache-save failures are reported even when sandbox disposal succeeds; subsequent disposal calls remain idempotent.