Skip to content

TypeError: Invalid URL: undefined/api/execute when using sandbox exec #8

@ItsWendell

Description

@ItsWendell

Description

When attempting to execute a command within a Worker sandbox environment, the request fails with a TypeError: Invalid URL. This suggests that the base URL might not be set or doesn't correctly resolve within the Worker's environment, resulting in an undefined.

Steps to Reproduce

  1. Configure a Worker project with a service binding for a sandbox service in wrangler.toml.

  2. Enable the nodejs_compat compatibility flag.

  3. In the Worker's source code, retrieve the service binding for the sandbox.

  4. Attempt to execute a command using the sandbox service like so:

    // Assuming 'env.Sandbox' is the service binding for the sandbox service.
    const sandbox = getSandbox(env.Sandbox, "sandbox-test");
    const result = await sandbox.exec("ls", []);
    console.log("result", result);
  5. Run the Worker using wrangler dev.

Expected Behavior

The sandbox.exec() method should successfully make an HTTP POST request to the configured sandbox service endpoint (e.g., http://127.0.0.1:8787/api/execute/) and return the result of the executed command.

Actual Behavior

The request fails, and the following error is thrown in the console:

[HTTP Client] Making POST request to undefined/api/execute/
✘ [ERROR] [HTTP Client] Request error: POST undefined/api/execute [TypeError: Invalid URL: undefined/api/execute]

Environment

  • Wrangler version: 4.22.0
  • Node.js version: v20.18.1
  • Operating System: Linux
  • Compatibility Date: 2024-05-01
  • Enabled Compatibility Flags: nodejs_compat, enable_request_signal

```log
[HTTP Client] Making POST request to undefined/api/execute/
✘ [ERROR] [HTTP Client] Request error: POST undefined/api/execute [TypeError: Invalid URL: undefined/api/execute]

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