Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reconnect to running command by PID fails after 2 minutes #1074

@sultantoor

Description

@sultantoor

Using E2B Cloud Service:

When trying to reconnect to a running command in the sandbox using its PID after 2 minutes, the command cannot be found. The reconnect functionality using Commands.connect(pid) does not work consistently, causing running background commands to appear lost.

To Reproduce
Steps to reproduce the behavior:

Start a long-running command in the sandbox using Commands.run(cmd, { background: true }).

Store the returned CommandHandle PID.

Wait for 2 minutes (or more).

Attempt to reconnect using Commands.connect(pid) with the stored PID.

Observe that the connection fails and the PID is reported as not found.

Expected behavior
I should be able to reconnect to any running command by its PID at any time, even after several minutes, and continue receiving stdout/stderr streams or send stdin.

Browser console output
[error] process with PID 12345 not found

Terminal commands & output
Example code used:
const handle = await sandbox.commands.run("long-running-script.sh", { background: true });
console.log("PID:", handle.pid);

// After 2 minutes
await sandbox.commands.connect(handle.pid);

Output:
Error: process with PID 12345 not found

Screenshots
N/A

Desktop (please complete the following information):

OS: Windows 11

Browser: Chrome 143

Version: 143.0.0.0

Smartphone (please complete the following information):

Device: N/A

Additional context
This bug breaks reconnecting to background commands, making it impossible to stream logs or interact with long-running tasks. It seems like the sandbox may be cleaning up the PID after 2 minutes, even though the command is still running.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions