Speed up Gitpod workspaces with Prebuilds
Learn how Gitpod Prebuilds run heavy setup steps on each push, store a snapshot, and let new workspaces start instantly.
24 Mar 2026, 15:16 UTC

Why Prebuilds matter
When you open a Gitpod workspace, the platform provisions a container, clones the repository, and then runs any tasks you defined in .gitpod.yml. For large projects that need to install dependencies, compile code, or generate assets, these steps can take several minutes each time a workspace starts. Gitpod Prebuilds move the heavy‑lifting part of that process to the server side: on every push to a configured branch, Gitpod runs the tasks you mark as prebuild, stores the resulting filesystem snapshot, and later restores that snapshot when a workspace is launched. The workspace then only needs to run the remaining command tasks, which are usually lightweight, so the time to a usable prompt drops from minutes to seconds.
Configuring Prebuilds in .gitpod.yml
A minimal configuration that enables prebuilds consists of three sections: the container image, the list of tasks, and a prebuild block that tells Gitpod which tasks to run during the snapshot build.
# .gitpod.yml
image: gitpod/workspace-full:latest
tasks:
- name: install-deps
init: npm ci
- name: build
command: npm run build
prebuild:
enable: true
tasks:
- init: npm ci
In this example:
- The
imageline selects the base container. - The
tasksarray defines two named tasks:install-deps(which runsnpm ciin itsinitphase) andbuild(which runsnpm run buildin itscommandphase). - The
prebuildblock enables the feature and repeats theinitstep ofinstall-deps. When Gitpod creates a prebuild snapshot, it executesnpm ciinside the container, captures the resultingnode_modulesdirectory, and stores it. - When a developer opens a workspace, Gitpod restores the snapshot (so
node_modulesis already present) and then proceeds to run any remaining tasks—here, thebuildtask’scommandphase—before dropping the user into the terminal.
How Prebuilds work under the hood
- On each push to a branch that matches the
prebuildconfiguration, Gitpod triggers a prebuild job. - The job starts a container from the specified image, checks out the repository at the pushed commit, and executes the tasks listed under
prebuild.tasks. - When those tasks finish, Gitpod takes a read‑only snapshot of the container’s filesystem (excluding certain transient directories like
/tmp) and stores it in its internal storage backend. - When a user clicks “New Workspace” or runs
gitpod.io/#https://github.com/owner/repo, Gitpod looks for the most recent snapshot for the branch, mounts it as the workspace’s root filesystem, and then starts the container. - The container’s entrypoint runs any tasks that were not part of the prebuild (the
commandparts of yourtaskslist) before presenting the shell prompt.
Comparison: regular start vs prebuild start
| Step | Regular workspace | Prebuild workspace |
|---|---|---|
| Container provisioning | Same for both | Same for both |
| Repository clone | Same for both | Same for both |
| Dependency install (npm ci) | Runs each time, ~2‑3 min | Restored from snapshot, ~0 s |
| Build step (npm run build) | Runs each time, ~1‑2 min | Runs each time (if not in prebuild), ~1‑2 min |
| Time to prompt | ~4‑5 min | ~1‑2 min (or less if build also prebuilt) |
Limits and common pitfalls
- Branch scope. Prebuilds are only generated for branches you explicitly enable (default branch, or any list you add under
prebuild.branches). If you push to a feature branch that isn’t covered, no snapshot is created and workspaces fall back to the regular startup flow. - Timeout. Each prebuild job has a hard limit of 30 minutes. If your init steps exceed that (for example, downloading large binaries or running a lengthy compile), the job is killed and no snapshot is stored. You’ll see a “prebuild timed out” status in the Gitpod dashboard.
- No secrets or runtime env. The prebuild environment does not have access to repository secrets,
$GITPOD_*variables, or any values you set in.gitpod.ymlundervars. Commands that need authentication (e.g.,npm login,docker login, or cloud‑provider CLI login) will fail or, worse, inadvertently log credentials if you mistakenly place them in the prebuild section. - Stale snapshots. Changing the base image, Dockerfile, or any system package that the init step depends on invalidates existing prebuilds. Gitpod does not automatically rebuild them; you must push a new commit (or trigger a manual rebuild) to generate fresh snapshots. Until then, workspaces will start with an outdated base image, which can cause subtle runtime errors.
- Storage growth. Each snapshot occupies space proportional to the files it captures. Large
node_modulesdirectories, compiled binaries, or generated assets can quickly increase storage usage. Monitor the “Prebuilds” tab in the Gitpod dashboard and consider pruning old branches or adjusting the snapshot scope (e.g., usingprebuild.ignorepatterns) to keep costs under control.
Verification steps
- Add a
.gitpod.ymlfile with a simple prebuild task, for example:
prebuild:
enable: true
tasks:
- init: echo "prebuild ran"
- Commit and push the file to the branch you want to monitor (usually
mainormaster). - Open the Gitpod dashboard, navigate to the “Prebuilds” view for the repository, and confirm that a job appears with a status of “finished” and a duration of a few seconds.
- Launch a new workspace from the same branch. In the terminal output, look for the line
prebuild ranappearing before the shell prompt. This indicates that the snapshot was restored and the prebuild task’s output was replayed. - Modify the
initcommand (e.g., change the echoed text), commit, and push again. Verify that the next prebuild job shows the updated output and that new workspaces display the new line.
If the prebuild job fails or never appears, check the branch filter, ensure the prebuild.enable flag is set to true, and inspect the job logs for error messages (commonly missing dependencies or timeout).
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.