*.cargo.app). defineWorker and defineApp deploy a source bundle directory that Cargo Hosting builds on deploy.
Define a worker
workers/webhook.ts
Define an app
apps/dashboard.ts
plan.
Environment variables
A worker reads its variables fromc.env, an app from import.meta.env.VITE_*. Both are baked in when the deployment is built, so a change needs a redeploy.
Set them on the resource — through env above, or its Environment tab in the Cargo app — or once for the whole workspace under Settings → Environment, which every worker and app inherits without declaring anything. A key set on the resource overrides the workspace value; an app only inherits non-secret VITE_ keys, since its bundle is served to the browser. See Secrets & environments.
Because the inheritance is automatic, a resource’s env takes env() or secret() and not workspaceEnv() — declaring a pointer here would only restate a variable the worker or app already receives. Leave a workspace variable out of env entirely.
defineWorker/defineApp are the deployable resource (the hosted slot).
Author the worker’s runtime code in TypeScript with createWorker from
@cargo-ai/worker-sdk at src/index.ts — bundles are uploaded as source and
built server-side: the hosting build runs npm ci then esbuilds the worker
entrypoint (esbuild transpiles TypeScript natively) or vite build for apps.
A pre-built index.js at the bundle root is still accepted for backwards
compatibility. Bundle sub-directories have their own package.json, so the
loader treats them as content to upload, not resource files to import.Cron triggers
A worker can be called on a schedule: each trigger describes the full request Cargo fires — cron (or Temporal’s@every shorthand), path, method (default POST), a JSON body, and headers. Set an authorization header and guard the route with standard Hono middleware (bearerAuth/basicAuth); ticks only fire once the worker has a promoted deployment.
Triggers can be set from the worker’s page in the Cargo app, via defineWorker (above), or with the CLI/API:
Calling the Cargo API
Create a workspace API token and add it to the worker as aCARGO_API_TOKEN secret environment variable — the Cargo API host is allowed without an outboundAllowlist entry. createCargoApi(env) from @cargo-ai/worker-sdk returns the fully-typed @cargo-ai/api client:
Custom integrations
A worker that serves the Custom Integration HTTP contract (createCustomIntegration from @cargo-ai/worker-sdk) can be registered in the connector catalog declaratively:
Scaffolding and deploying standalone
You can also scaffold and ship bundles directly with the CLI:my-worker).
