Skip to content

Shell steps fail when the runner work directory contains spaces #4874

Open

Description

@mrdimidium

Describe the bug

The built-in argument templates for bash, sh, and python interpolate the generated script path without quoting it:

["bash"] = "--noprofile --norc -e -o pipefail {0}",
["sh"] = "-e {0}",
["python"] = "{0}"

Source: ScriptHandlerHelpers.cs v2.338.2.

In ScriptHandler.cs, the resolved script path is substituted into the argument string:

resolvedScriptPath = StepHost.ResolvePathForStepHost(
  ExecutionContext, scriptFilePath).Replace("\"", "\\\"");

var arguments = string.Format(argFormat, resolvedScriptPath);

Escaping embedded double quotes does not surround the path with quotes. A generated script path containing spaces can therefore be split into multiple arguments.

To Reproduce

  1. Configure a self-hosted Linux or macOS runner with a work directory containing a space.
  2. Confirm that generated step scripts are placed in a temporary directory whose full path contains that space.
  3. Run the following workflow. The Python case requires python on PATH.
name: Script paths containing spaces

on:
  workflow_dispatch:

jobs:
  reproduce:
    runs-on: self-hosted
    steps:
    - name: Bash
      shell: bash
      run: printf '%s\n' 'bash step executed'
    - name: POSIX shell
      if: always()
      shell: sh
      run: printf '%s\n' 'sh step executed'
    - name: Python
      if: always()
      shell: python
      run: print("python step executed")

This concerns the generated script path, not merely the step's working-directory.

Expected behavior

The full script path is passed to the interpreter as one argument, and the step executes successfully even when the runner work/temp path contains spaces.

Runner Version and Platform

Source version inspected: v2.338.2.

Target platforms for reproduction: self-hosted Linux and macOS. No official Runner installation or specific OS release has been used for end-to-end verification yet.

What's not working?

For a script at:

/tmp/runner work/_temp/example.sh

the built-in Bash template produces:

--noprofile --norc -e -o pipefail /tmp/runner work/_temp/example.sh

The suspected failure is that the interpreter treats /tmp/runner as the script filename instead of receiving the complete path as one argument.

The cmd, pwsh, and powershell templates have different quoting conventions and are not part of this specific finding.

Activity

  1. added
    bug
    on Nov 19, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions