Skip to content

SandboxClient.run() returns hardcoded exit codes instead of actual values #631

@parteeksingh24

Description

@parteeksingh24

Summary

The sandboxRun() function in @agentuity/server hardcodes exit codes instead of retrieving the actual values from the execution.

Location

packages/server/src/api/sandbox/run.ts (compiled to dist/api/sandbox/run.js)

Current Behavior

if (finalStatus === 'terminated') {
    return { sandboxId, exitCode: 0, ... };  // Hardcoded
}
if (finalStatus === 'failed') {
    return { sandboxId, exitCode: 1, ... };  // Hardcoded
}

The function polls sandboxGet() for status but never calls executionGet() to retrieve the actual exit code from the execution info.

Expected Behavior

run() should return the actual exit code from the process, similar to how SandboxInstance.execute() does it by calling executionGet() and returning finalResult.exitCode.

Workaround

Use client.create() + sandbox.execute() instead of client.run() to get real exit codes:

const sandbox = await client.create(options);
const execution = await sandbox.execute({ command: ['bun', 'run', 'script.ts'] });
console.log(execution.exitCode); // Real exit code
await sandbox.destroy();

Impact

Scripts that exit with non-zero codes (e.g., process.exit(2)) will incorrectly report exitCode: 0 when using client.run().

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions