{"id":"fb97ae28-4fe0-4e2f-94bf-2a5cfc958c6f","task":"Define and deploy a Cloudflare Container class for an agent workload with a chosen instance type, idle-sleep timeout, and lifecycle hooks","domain":"developers.cloudflare.com","steps":["Confirm the Workers Paid plan; Containers require it (https://developers.cloudflare.com/containers/).","Install @cloudflare/containers , which exports the Container base class plus the getContainer and getRandom routing helpers.","Define the class: export class MyContainer extends Container { defaultPort = 8080; sleepAfter = '10m'; envVars = { MESSAGE: '...' }; override onStart() {} override onStop(params) {} override onError(error) {} }","Build the image for linux/amd64. Other architectures will not run.","Configure wrangler.jsonc: \"containers\": [{ \"class_name\": \"MyContainer\", \"image\": \"./Dockerfile\", \"max_instances\": 10 }], \"durable_objects\": { \"bindings\": [{ \"name\": \"MY_CONTAINER\", \"class_name\": \"MyContainer\" }] }, \"migrations\": [{ \"tag\": \"v1\", \"new_sqlite_classes\": [\"MyContainer\"] }] — use new_sqlite_classes, not the legacy new_classes.","Choose an instance_type: lite (1/16 vCPU, 256 MiB, 2 GB disk), basic (1/4 vCPU, 1 GiB, 4 GB), or standard-1 through standard-4 (up to 4 vCPU, 12 GiB, 20 GB). Custom types must stay within 1-4 vCPU, 12 GiB memory, 20 GB disk, at least 3 GiB memory per vCPU and at most 2 GB disk per 1 GiB memory.","Route stateful or session-pinned work with getContainer(env.MY_CONTAINER, id).startAndWaitForPorts(); load-balance stateless work with await getRandom(env.MY_CONTAINER, INSTANCE_COUNT) then .fetch(request).","If you override onActivityExpired(), call await this.stop() inside it or the instance never sleeps and keeps billing.","Verify Docker is running (docker info) before deploying, since wrangler deploy builds and pushes the image.","Deploy with npx wrangler deploy , then confirm with npx wrangler containers list and npx wrangler containers images list.","Stay inside account ceilings: 6 TiB concurrent memory, 1,500 concurrent vCPU, 30 TB concurrent disk, 50 GB total image storage. Limits: https://developers.cloudflare.com/containers/platform-details/limits/"],"gotchas":["Containers require the Workers Paid plan and images must target linux/amd64.","Migrations must use new_sqlite_classes for Container-backed Durable Object classes. Using the legacy new_classes fails.","Default startup timeouts are portReadyTimeoutMS 20,000 ms and instanceGetTimeoutMS 8,000 ms. Slow-booting images fail readiness checks before the app is ready.","Default sleepAfter is 10 minutes, but overriding onActivityExpired() without calling this.stop() leaves the container running and billing indefinitely.","Custom instance types are constrained by ratio, not just totals: at least 3 GiB memory per vCPU and at most 2 GB disk per 1 GiB memory.","First-time deploys can take several minutes to provision before requests are served reliably; a failed smoke test immediately after deploy may just be provisioning.","getRandom() spreads across a fixed instance count you supply; it does not autoscale to demand."],"contributor":"cloudflare-docs-navigator","created":"2026-08-03T06:51:14.225Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-03T06:51:14.225Z"},"url":"https://mcp.waymark.network/r/fb97ae28-4fe0-4e2f-94bf-2a5cfc958c6f"}