Skip to content

E2B sandbox: redundant Files-API make_dir on workspace root at fresh session start can hang/abort startup #3844

Description

@devin-ai-integration

Please read this first

Describe the bug

On every fresh (non-preserved) E2B sandbox session start, E2BSandboxSession._prepare_backend_workspace() first calls _ensure_workspace_root(), which performs a Files-API files.make_dir('/workspace'), and then runs _prepare_workspace_root_for_exec(), which performs a command-API mkdir -p -- /workspace.

The Files-API make_dir is redundant: the command-API mkdir -p that immediately follows is the actual guarantee that the workspace root exists (it sets _workspace_root_ready and gates cwd usage). The preserved-start branch already relies solely on the command-API path and never calls the Files-API make_dir.

The redundant call is also a real failure mode: when the E2B envd daemon is degraded, files.make_dir on an already-existing directory (templates commonly ship /workspace) can hang and eventually fail with httpcore.ReadTimeout → e2b TimeoutExceptionWorkspaceArchiveWriteErrorWorkspaceStartError, aborting the whole session start — even though the subsequent command-API mkdir -p would have succeeded.

Debug information

  • Agents SDK version: v0.18.2 (also reproduces on latest main; the file is identical)
  • Python version: 3.12
  • File: src/agents/extensions/sandbox/e2b/sandbox.py (_prepare_backend_workspace, _ensure_workspace_root, _sandbox_make_dir)

Repro steps

  1. Use an E2B template whose filesystem already contains the workspace root (e.g. /workspace).
  2. Start a fresh E2BSandboxSession while envd is degraded/slow (or observe the duplicate calls with a Files-API spy in normal conditions).
  3. Startup performs Files-API make_dir('/workspace') before the command-API mkdir -p -- /workspace; if the Files-API call times out, startup raises WorkspaceStartError and the run aborts.

Expected behavior

Fresh session start should rely on the command-API mkdir -p (as the preserved-start branch already does) and not perform a redundant Files-API make_dir on the workspace root, so a degraded Files API cannot abort startup when the directory already exists or can be created via the command API.

I have a small patch for this (drop the redundant _ensure_workspace_root() call and collapse both branches onto _prepare_workspace_root_for_exec(), plus a regression test) and will open a PR referencing this issue.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions