Skip to content

fix(exec): resolve login shell PATH when exec host defaults to "sandbox" without sandbox runtime #41549

@yarnovo

Description

@yarnovo

Bug Summary

When tools.exec.host is not configured (defaults to "sandbox") and agents.defaults.sandbox.mode is "off" (default), the exec tool enters a "phantom sandbox" state where:

  • No Docker sandbox is used (mode=off)
  • Login shell PATH resolution does NOT run (only triggers for host === "gateway")
  • process.env.PATH is used directly, which on macOS LaunchAgent is incomplete (missing nvm/fnm/volta versioned bin dirs)

This causes node (and other version-manager-installed tools) to be command not found when agents execute shell commands.

Root Cause

Two separate issues contribute:

1. LaunchAgent plist PATH construction is incomplete for nvm

The gateway's LaunchAgent plist includes ~/.nvm in PATH but NOT ~/.nvm/versions/node/<version>/bin/. The ~/.nvm directory itself doesn't contain node binaries — nvm requires sourcing nvm.sh to set the versioned PATH entry.

2. exec tool doesn't resolve login shell PATH in "phantom sandbox" mode

In src/agents/bash-tools.exec.ts:384:

if (!sandbox && host === "gateway" && !params.env?.PATH) {
  const shellPath = getShellPathFromLoginShell({...});
  applyShellPath(env, shellPath);
}

The login shell PATH resolution only runs when host === "gateway". When host defaults to "sandbox" but no actual sandbox runtime exists (mode=off, Docker not running), the code falls through without resolving the login shell PATH.

Suggested fix for issue 2

// Change condition to also cover "phantom sandbox" case:
if (!sandbox && (host === "gateway" || host === "sandbox") && !params.env?.PATH) {

Reproduction

  1. Install Node.js via nvm on macOS
  2. Run OpenClaw gateway as LaunchAgent (default setup)
  3. Do NOT configure tools.exec.host (leave default)
  4. Have an agent exec node --version
  5. Result: command not found: node

Workaround

Set tools.exec.host to "gateway" in ~/.openclaw/openclaw.json:

{
  "tools": {
    "exec": {
      "host": "gateway"
    }
  }
}

Impact

Affects all users who:

  • Install Node.js via nvm, fnm, or volta
  • Run gateway as macOS LaunchAgent (default)
  • Don't explicitly configure tools.exec.host

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions