Skip to content
Cloudflare Docs

Container Package

When writing code that interacts with a container instance, you can either use a Durable Object directly or use the Container module importable from @cloudflare/containers.

import { Container } from "@cloudflare/containers";
class MyContainer extends Container {
defaultPort = 8080;
sleepAfter = "5m";
}

We recommend using the Container class for most use cases.

Install it with npm install @cloudflare/containers.

The Container class extends DurableObject so all Durable Object functionality is available. It also provides additional functionality and a nice interface for common container behaviors, such as:

  • sleeping instances after an inactivity timeout
  • making requests to specific ports
  • running status hooks on startup, stop, or error
  • awaiting specific ports before making requests
  • setting environment variables and secrets

See the Containers GitHub repo for more details and the complete API.