Running your code
Deploying
A deployment is a pinned, content-addressed build of your tasks. Develop with serve, build with deploy, and make a build current in an environment.
On this page
You run your code two ways:
| Command | For | What it runs |
|---|---|---|
durable-compute serve | Development on your computer | Your source as it is, in the stock Node and Python images, with no third-party packages. A bundled project can load its packages from your own node_modules. |
durable-compute deploy | Staging, production and previews | One image per runtime, with your locked dependencies installed, pinned by image ID. |
Both produce a deployment: an ID made from a hash of your code and task definitions. The same code gives the same ID, and any change gives a new one.
Project layout#
A task project is a folder with a manifest, your task code, and a copy of the SDK's runtime:
my-tasks/├── manifest.json├── sdk/ the sdk folder of the Bok Joy checkout│ ├── node/│ └── python/└── tasks/ ├── email.mjs └── lib/ └── templates.mjs- The
sdkfolder holds the runners that start your handlers:sdk/node/runner.mjsfor Node tasks andsdk/python/durable_compute/runner.pyfor Python tasks. Copy it from your checkout of the Bok Joy repository. A deploy refuses a manifest whose runtime has no runner. It also refuses a copy ofsdk/nodefrom before delayed triggers, whether or not your tasks delay one: that copy drops a trigger'sdelayanddebounce, so the child would start at once. It refuses a copy of either SDK from before lifecycle hooks the same way, since that copy would run no failure hook. The message names the file. Copy thesdkfolder again from the Bok Joy checkout you deploy with. - Entrypoints are relative to the project root, and stay inside it.
- Each task's top-level folder goes into the bundle whole. For
tasks/email.mjs, that is everything undertasks/. An entrypoint at the project root brings the root's files instead. Imports must stay inside those folders: an import of../shared/fromtasks/is not bundled. To import from anywhere in the project, bundle it instead. - Some names are skipped: anything starting with
., andnode_modules,targetand__pycache__. - Symbolic links are refused.
A bundle holds at most 10,000 files and 64 MiB, with no file over 16 MiB.
Develop with serve#
From the project root, start a control plane with your manifest:
durable-compute serve --manifest manifest.jsonserve bundles the code and makes it current in dev. Restart it after an edit to run the new code. A restart never undoes a promotion you made with deploy --env or environments promote. The quickstart walks through it.
serve runs no third-party packages, so it refuses a manifest that declares dependencies. Use deploy for those. A manifest with a build section is the exception: see Develop a bundled project.
Build a deployment#
durable-compute deploy --manifest manifest.json --env stagingdeploy builds one image per runtime your manifest uses, from the base images node:24-bookworm-slim and python:3.12-slim, and registers the deployment. With --env, it also makes the deployment current there. Without it, it only registers. It prints the deployment_id, and each image's ID, platform, base image and locked packages.
- Base images must already be on your computer. Deploy never pulls them.
- Builds are isolated. Only the dependency install step has network access. The image runs as an unprivileged user, with your code and packages read-only.
- The platform defaults to your Docker's own. Bok Joy's cloud workers are
linux/amd64, so pass--platform linux/amd64on Apple silicon.
Declare dependencies#
Add a dependencies object to the manifest, pointing at your lock files:
{ "tasks": [...], "dependencies": { "node": {"package_json": "tasks/package.json", "lockfile": "tasks/package-lock.json"}, "python": {"requirements": "jobs/requirements.txt"} }}| Runtime | Rules |
|---|---|
| Node | A package-lock.json (lockfileVersion 2 or 3) beside package.json. Every Node entrypoint must sit inside that folder. Packages come only from registry.npmjs.org, each with a strong integrity hash. Installed with npm ci --omit=dev --ignore-scripts, so install scripts never run. If your lock was made with npm's legacy-peer-deps=true, add "legacy_peer_deps": true beside lockfile. Deploy never reads .npmrc, which can hold registry tokens. |
| Python | A requirements.txt where every line is name==version with a --hash, for example from pip-compile --generate-hashes. List transitive packages too. Installed from wheels only, with pip install --require-hashes --only-binary=:all: --no-deps. |
A declaration without a lock, or Python requirements without hashes, is refused before anything is built. Locks are part of the bundle, so changing one makes a new deployment.
System packages#
Programs your tasks run, such as ffmpeg or a browser, go in dependencies.apt. Deploy installs them with apt into every runtime image:
"dependencies": { "node": {"package_json": "package.json", "lockfile": "package-lock.json"}, "apt": ["ffmpeg", "chromium", "fonts-liberation"]}- Names are Debian package names, optionally pinned as
name=version. Up to 64. Anything else is refused before the build. - The base images must be Debian. The default
node:24-bookworm-slimis Debian 12 andpython:3.12-slimis Debian 13, so their package versions differ. Check a version withdocker run --rm <base image> apt-cache policy <name>. - The packages are one layer straight on the base image. Deploys that change only your code reuse it from Docker's build cache. Changing the list, or the base image, installs them again.
- The image ID pins what was installed. apt checks each package against Debian's signed archive. The list is part of the bundle, so changing it makes a new deployment.
- They are only in deploy-built images.
servewith Docker refuses a manifest withdependencies.apt.serve --executor nativeuses the programs on your own machine.
For Puppeteer, install chromium and fonts-liberation and launch Debian's Chromium with --no-sandbox. Task containers drop every Linux capability, so Chromium's own sandbox cannot start:
import puppeteer from 'puppeteer-core'; const browser = await puppeteer.launch({ executablePath: '/usr/bin/chromium', args: ['--no-sandbox', '--disable-gpu'],});Use puppeteer-core, which has no browser download, or set PUPPETEER_SKIP_DOWNLOAD. Install scripts never run in a deploy, so puppeteer would find no browser of its own.
What a task container gets#
Each attempt runs in a fresh container, as user 65534, with a read-only root:
| CPU and memory | The task's machine. Swap is off. |
/tmp | Writable, sized at half the machine's memory. It counts against that memory. |
HOME | /tmp, for tools that keep caches or settings in your home folder. |
| Processes and threads | Up to 1,024, enough for Chromium and ffmpeg. |
| Network | Outbound internet, with private networks blocked. |
Bundle a TypeScript project#
Add a build section, and deploy bundles your Node tasks with esbuild instead of copying folders. A project laid out for Trigger.dev deploys as it is: tasks in src/trigger can import ../../lib, @/ paths from your tsconfig.json, and JSON files.
{ "tasks": [ {"id": "stock.record", "kind": "task", "runtime": "node", "entrypoint": "src/trigger/stock.ts", "handler": "recordStock"} ], "dependencies": { "node": {"package_json": "package.json", "lockfile": "package-lock.json"} }, "build": { "external": ["sharp"], "prisma": {"schema": "prisma/schema.prisma", "mode": "legacy"} }}| Field | What it does |
|---|---|
dirs | Folders of task files written the Trigger.dev way. Deploy finds the tasks they export: see Find tasks in folders. Up to 20. |
workflows | IDs of tasks dirs finds that wait on child runs. Deploy registers each one as a workflow: see Workflows from found tasks. Up to 1,000. |
external | Packages installed in the image from your lockfile, instead of bundled into your code. Native modules such as sharp, @napi-rs/canvas and ssh2 belong here, and so do packages that read their own files at run time, such as pdfjs-dist. Up to 100. |
tsconfig | The tsconfig.json to use, relative to the project root. Without it, esbuild uses the nearest one above each file. |
prisma | Generates Prisma Client in the image. schema is the schema's path. mode is legacy, for the prisma-client-js generator. |
build can be empty: "build": {} bundles everything, with no externals.
Find tasks in folders#
With build.dirs, deploy finds tasks defined with task(), schemaTask() and schedules.task() from @bokjoy/sdk/trigger, as Trigger.dev's dirs does. See Define tasks the Trigger.dev way for the code.
{ "dependencies": { "node": {"package_json": "package.json", "lockfile": "package-lock.json"} }, "build": {"dirs": ["src/trigger"], "external": ["sharp"]}}- Every task file in the folders is loaded, in subfolders too:
.ts,.mts,.cts,.tsx,.js,.mjs,.cjsand.jsx. Type declarations,*.test.*and*.spec.*files,node_modulesand names starting with.are skipped. - Each exported task becomes a manifest entry: its ID, its file as
entrypoint, its export's name ashandler, and its options as fields. A task must be exported, as in Trigger.dev. - An
initfile at the top of a folder, such assrc/trigger/init.ts, loads before every task, as Trigger.dev'sinit.tsdoes. Each folder may have one. - Lifecycle hooks are found too: a task's own, and every one
tasks.onFailureand the like register while the files load. Each task's entry lists the ones that run after a run ends inhooks. - Entries you write in
tasksstay. An ID defined twice, in two files or in a file and the manifest, is refused with both places. - Deploy refuses what Bok Joy cannot honor yet, with the file and line of each task:
catchError,middleware,onWaitand the other hooks Bok Joy does not have,ttl, and any option it does not know. It lists every problem at once, so one deploy shows the whole list. - The manifest's
defaultsapply to found tasks, as to the ones you write:defaults.timeout_msto a task without its ownmaxDuration, anddefaults.retryto a task without its ownretry.
The deploy report's bundle lists each task it found under discovered, with the file, line and kind, and the init files under init.
To find the tasks, deploy runs your task files' top-level code once, in the bundler's sandbox: no network, none of your environment variables, and your project read-only with nothing in it executable. The only variables set are the bundler's own: PATH, HOME, HOSTNAME, NODE_VERSION and YARN_VERSION. It gets at most 2 CPUs, 2 GiB of memory and 256 processes. Every package is replaced by a stand-in, so a file that only imports and configures clients loads. Only your task files and Node's builtins load: a file loaded by absolute path is refused. Code that needs a real value at load time fails, and the deploy names its file and line. For example, process.env.HOSTS.split(',') at the top of a file fails, because HOSTS is not set. Read variables inside run instead.
A task ID must be the one the run sees, so deploy refuses an ID built from a package's value, or from an environment variable discovery does not set, such as `report-${process.env.REGION}`. Once any file has read a variable that is not set, an ID with undefined in it is refused, wherever the read happened. Write the ID as a literal, or build it from your own code.
Discovery's own checks catch mistakes, such as a file that prints or exits early. They do not stop a project that sets out to fake what discovery reports. The sandbox, and deploy's checks of every task it is told about, are what hold: an ID, an export, a machine preset or an option deploy does not accept is refused however it was reported.
The top-level code must finish loading within 2 minutes, or the build timeout if that is shorter. Deploy stops discovery, and names the file it was loading, when a file runs past that, runs out of memory, logs more than 16 MiB, or exits the process. Move long work into run.
Stopping deploy with Ctrl-C stops discovery too, even in a file that ignores the signal. A second Ctrl-C exits at once. A deploy that is killed outright leaves its discovery running until 15 seconds past that limit at most, and the next deploy on the same machine stops it sooner.
@bokjoy/sdk and @bokjoy/sdk/trigger load your project's own copy of the SDK, sdk/node, never a package from the registry. Keep it the copy from the Bok Joy checkout you deploy with: an import of a name your copy does not have fails the deploy with the name. A file that still imports @trigger.dev/sdk is refused with its line.
build.dirs names up to 20 folders, with up to 5,000 task files.
Workflows from found tasks#
Deploy registers the tasks it finds as plain tasks. A plain task that calls triggerAndWait or batchTriggerAndWait holds its process until the children finish, as on self-hosted Trigger.dev, so it needs no entry here. See In a plain task. With a copy of sdk/node from before held waits, such a wait throws instead.
To make a task a workflow, which frees its machine while it waits, name it in build.workflows:
{ "build": {"dirs": ["src/trigger"], "workflows": ["pos.poll-all", "inventory.unpause"]}}Each attempt of a workflow ends at a wait, and the run replays the task from the top when the children finish. See Waiting on child runs for what that means for your code.
Deploy refuses build.workflows without build.dirs, and it refuses an entry that:
- names no task that
build.dirsfinds, such as a typo, - appears twice,
- names a task the manifest's own
tasksdefine, which sets"kind": "workflow"on its entry instead, - or is not a task ID.
It also refuses build.workflows when your project's copy of the SDK, sdk/node, is too old to end an attempt at a wait without throwing. Copy the sdk folder from the Bok Joy checkout you deploy with.
Each of these is refused before anything is built.
A wait's child must be a task. A task in build.workflows can still be started by trigger or batchTrigger, but not waited on.
What the bundle holds#
- Entrypoints can be
.ts,.mts,.cts,.tsx,.js,.mjs,.cjsor.jsx. Each compiles to an.mjsfile beside its source, sosrc/trigger/stock.tsruns assrc/trigger/stock.mjs. Code that several tasks share goes intochunks/. A handler is still a named export. - Imports can reach anywhere in the project root. Nothing outside it is read, and symbolic links are refused.
- Packages are bundled from your lockfile. Every package your tasks import must be in
package.jsondependencies, notdevDependencies, and in the lock. A package that is not installed fails the deploy with its name. - Externals are installed with what they depend on, and nothing else. The image gets each external and its locked dependencies for the image's platform, not your whole
node_modules. Each external must be a top-level entry in the lock, and every import of it must load that copy. - An import esbuild cannot resolve inside a
try/catchis left for Node to find missing, as the code expects. node-fetch's optionalencodingis one. The deploy report lists these underoptional_unresolved.
Prisma#
prismaand@prisma/clientmust both be in the lock, at the same version.@prisma/clientbecomes an external on its own.- The client is generated in the image, with the query engine for the image's platform. On Apple silicon,
--platform linux/amd64builds the engine for Bok Joy's cloud workers. - The generator must not set
output. The client is loaded fromnode_modules/.prisma, whereprisma generatewrites it by default. - The image gets OpenSSL 3 and CA certificates, which the engine loads. Your connection string comes from an environment variable, as in the schema's
env().
Isolation and pinning#
- esbuild 0.28.2 is pinned by a lockfile inside Bok Joy, and runs in Docker on the same base image as your tasks.
- Only installs have network access: the bundler's
npm ci, your lockfile'snpm ci, the OpenSSL install,prisma generateand yourdependencies.aptpackages. esbuild itself has none. - Your project is mounted read-only, as your user, to find the files your entrypoints import. Only those files, the
tsconfig.jsonandpackage.jsonfiles that shape how they resolve, and the lock files go into the build. - The deployment ID still hashes the content. The same sources give the same ID. A change to any imported file, the lock, the schema or the manifest gives a new one.
The bundle step reads at most 20,000 files and 256 MiB from your project. The compiled bundle has the same limits as any other.
deploy prints a bundle object beside the images: the esbuild version, each entrypoint's compiled file, the packages it bundled, the externals, and any warnings.
Develop a bundled project#
serve --manifest bundles the same way, for your Docker's own platform. Restart it to bundle an edit.
- With no
externaland noprisma, the bundle runs under either executor. - With them, use
--executor native. Node then loads them from your project's ownnode_modules, astrigger devdoes. Runnpm ciandnpx prisma generatefirst, and keep--bundlesinside the project. The default,.durable/bundles, is. - The Docker executor refuses them, because its stock image has no packages. Test the real image with
deploy, thenserve --deployment <id>and a worker.
npm cinpx prisma generatedurable-compute serve --manifest manifest.json --executor nativeMake it current#
durable-compute environments promote prod --deployment <deployment id>Promoting needs no rebuild: production runs exactly the images you tested. Runs already accepted keep the deployment they started on, so a deploy never changes a running workflow's code. See Environments.
Run it on cloud workers#
Cloud workers run your deployment's own images, plus Bok Joy's worker agent. The operator builds and pushes these worker images once per deployment and runtime with durable-compute worker-image build --push. Bok Joy then starts machines from them on demand.