MCPcopy Create free account
hub / github.com/cloudflare/computer / ContainerExample

Class ContainerExample

examples/worker-shell/src/index.ts:51–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49// on the same door by id. The options callback runs after super(...),
50// so it can read self.ctx / self.env.
51export class ContainerExample extends withWorkspace(class extends DurableObject<Env> {}, (self) => {
52 const { ctx, env } = self as unknown as { ctx: DurableObjectState; env: Env };
53 return {
54 // ctx.storage.sql.exec returns a narrower row type than
55 // DurableObjectStorageLike declares; the runtime shape
56 // matches. Cast through unknown to bypass invariance.
57 storage: ctx.storage as unknown as DurableObjectStorageLike,
58 backends: [
59 new WorkerShellBackend({
60 loader: env.LOADER,
61 workspace: { binding: "ContainerExample", id: ctx.id.toString() },
62 ctx,
63 }),
64 ],
65 // Mount the Bucket binding at /workspace/r2. Seed it with
66 // `npm run seed:r2` so the first read returns "hello world".
67 // The bucket is read-only; writes under /workspace/r2
68 // reject with EROFS.
69 mounts: {
70 "/workspace/r2": R2Bucket(env.Bucket),
71 },
72 };
73}) {}
74
75// ---------------------------------------------------------------
76// Worker HTTP surface (mirrors examples/container)

Callers

nothing calls this directly

Calls 3

withWorkspaceFunction · 0.90
R2BucketFunction · 0.90
toStringMethod · 0.65

Tested by

no test coverage detected