Skip to content

Container not started before containerFetch: missing sandbox.start() call #291

@amit-blotout

Description

@amit-blotout

Problem

Every request fails with:

Error proxying request to container <id>: Error: The container is not running, consider calling start()

Root Cause

The sandbox middleware in src/index.ts calls getSandbox() to get the sandbox instance but never calls sandbox.start() before setting it in the Hono context:

// Current (broken)
const sandbox = getSandbox(c.env.Sandbox, 'moltbot', options);
c.set('sandbox', sandbox);

When a subsequent handler calls sandbox.containerFetch() or sandbox.wsConnect(), the container hasn't been booted yet, causing the error.

Fix

Add await sandbox.start() before setting the sandbox in context:

const sandbox = getSandbox(c.env.Sandbox, 'moltbot', options);
await sandbox.start();
c.set('sandbox', sandbox);

start() is idempotent — it is a no-op if the container is already running, so calling it on every request is safe.

Steps to Reproduce

  1. Deploy the worker to Cloudflare
  2. Make any request to the worker URL
  3. Observe the 500 error and the "container is not running" log in Workers observability

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions