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 TimeoutException → WorkspaceArchiveWriteError → WorkspaceStartError, 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
- Use an E2B template whose filesystem already contains the workspace root (e.g.
/workspace).
- Start a fresh
E2BSandboxSession while envd is degraded/slow (or observe the duplicate calls with a Files-API spy in normal conditions).
- 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.
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-APIfiles.make_dir('/workspace'), and then runs_prepare_workspace_root_for_exec(), which performs a command-APImkdir -p -- /workspace.The Files-API
make_diris redundant: the command-APImkdir -pthat immediately follows is the actual guarantee that the workspace root exists (it sets_workspace_root_readyand gatescwdusage). The preserved-start branch already relies solely on the command-API path and never calls the Files-APImake_dir.The redundant call is also a real failure mode: when the E2B envd daemon is degraded,
files.make_diron an already-existing directory (templates commonly ship/workspace) can hang and eventually fail withhttpcore.ReadTimeout→ e2bTimeoutException→WorkspaceArchiveWriteError→WorkspaceStartError, aborting the whole session start — even though the subsequent command-APImkdir -pwould have succeeded.Debug information
v0.18.2(also reproduces on latestmain; the file is identical)src/agents/extensions/sandbox/e2b/sandbox.py(_prepare_backend_workspace,_ensure_workspace_root,_sandbox_make_dir)Repro steps
/workspace).E2BSandboxSessionwhile envd is degraded/slow (or observe the duplicate calls with a Files-API spy in normal conditions).make_dir('/workspace')before the command-APImkdir -p -- /workspace; if the Files-API call times out, startup raisesWorkspaceStartErrorand 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-APImake_diron 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.