Skip to content

[Bug] E2B sandbox ignores WorkspaceSpec.root and does not rebind RemoteSnapshotClient #4080

Closed

Description

@chcodex

Environment

  • Repository: agentscope-ai/agentscope-java
  • Baseline: upstream/main at 7d84cff02 (2026-11-09)
  • Module: agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b

Bug 1: WorkspaceSpec.root is ignored by the E2B sandbox client

E2bSandboxClient.create(WorkspaceSpec, SandboxSnapshotSpec, E2bSandboxClientOptions) only uses E2bSandboxClientOptions.workspaceRoot (default /home/user) and never reads WorkspaceSpec.root.

Relevant code on main:

  • E2bSandboxClient#create (E2bSandboxClient.java:58)
  • E2bSandboxClient#resume (E2bSandboxClient.java:90)
  • E2bSandbox#doExec uses getWorkspaceRoot() as the envd process cwd

As a result, if an application passes WorkspaceSpec.root=/root/workspace, shell commands still run with pwd == /home/user.

The same wrong root also affects:

  • resume(): a persisted E2bSandboxState keeps the old workspaceRoot (/home/user) even when the current spec points at /root/workspace.
  • isWorkspaceOnVolume(): volume coverage is computed from the options root instead of the effective root, so a volume mounted at /root/workspace is incorrectly reported as not covering the workspace.

Bug 2: RemoteSnapshotClient is not rebound on deserialization

SandboxClient defines a two-argument default method:

default SandboxState deserializeState(String json, SandboxSnapshotSpec snapshotSpec) {
    return deserializeState(json);
}

E2bSandboxClient does not override it, unlike DockerSandboxClient / KubernetesSandboxClient, and does not re-inject the runtime client into a deserialized RemoteSandboxSnapshot.

After a state round-trip, RemoteSandboxSnapshot.client == null, so isRestorable() / persist() fails with:

java.lang.IllegalStateException: RemoteSnapshotClient is not bound to snapshot id: snap-1
    at ...RemoteSandboxSnapshot.requireClient(RemoteSandboxSnapshot.java:112)

Reproduction

New regression tests were added under agentscope-extensions-sandbox-e2b/src/test/java/io/agentscope/extensions/sandbox/e2b/:

  • E2bSandboxWorkspaceRootTest
    • createUsesWorkspaceSpecRootOverOptionsDefault
    • resumeUsesWorkspaceSpecRootOverPersistedStateRoot
    • createMarksWorkspaceOnVolumeWhenSpecRootIsCoveredByMount
  • E2bSandboxClientRemoteSnapshotTest
    • deserializeStateRebindsRemoteSnapshotClient

Against 7d84cff02, all four fail:

expected: </root/workspace> but was: </home/user>
workspace root /root/workspace is covered by the configured volume mount
  ==> expected: <true> but was: <false>
Unexpected exception thrown: SandboxException$SnapshotException: Remote exists check failed
Caused by: java.lang.IllegalStateException: RemoteSnapshotClient is not bound to snapshot id: snap-1

Expected behavior

  1. WorkspaceSpec.root is authoritative when non-blank.
  2. create() persists the effective root; resume() synchronizes the state root and recomputes workspaceOnVolume from that root.
  3. deserializeState(json, snapshotSpec) rebinds the current RemoteSnapshotClient into a deserialized RemoteSandboxSnapshot, preserving the persisted snapshot id.

Verification

mvn -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b \
  test \
  -Dtest=E2bSandboxWorkspaceRootTest,E2bSandboxClientRemoteSnapshotTest,E2bVolumeMountTest,E2bSandboxOptionsAndStateTest,E2bSandboxRecoveryTest,E2bSandboxEnvsTest,E2bEnvdSandboxUrlTest \
  -DfailIfNoTests=false -Dcheckstyle.skip=true -Dspotless.check.skip=true

After the fix: Tests run: 67, Failures: 0, Errors: 0, spotless:check passes.

Activity

  1. added a commit that references this issue on Nov 11, 2026
    c887528
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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