Skip to content

fix: handle spaces in paths when running shell commands#377

Merged
HenryNdubuaku merged 2 commits intocactus-compute:mainfrom
adithya-n05:fix/handle-spaces-in-paths
Feb 23, 2026
Merged

fix: handle spaces in paths when running shell commands#377
HenryNdubuaku merged 2 commits intocactus-compute:mainfrom
adithya-n05:fix/handle-spaces-in-paths

Conversation

@adithya-n05
Copy link
Copy Markdown
Contributor

@adithya-n05 adithya-n05 commented Feb 21, 2026

Fixes #379

Problem

The cactus build command fails when the repo is cloned into a directory path containing spaces (e.g., /Users/name/Programming Projects/cactus).

Error:

/bin/sh: /Users/name/Programming: No such file or directory
Build failed

The issue is in run_command() which passes string paths to subprocess.run() with shell=True, causing the shell to interpret spaces as argument separators.

Solution

Changed run_command() to use shell=False (the default) by converting string paths to a list. This avoids shell interpretation entirely and handles paths with spaces correctly.

Before:

result = subprocess.run(cmd, cwd=cwd, shell=isinstance(cmd, str))

After:

if isinstance(cmd, str):
    cmd = [cmd]
result = subprocess.run(cmd, cwd=cwd)  # shell=False by default

Why this approach?

  • Cross-platform: Works on both Unix and Windows (unlike shlex.quote() which uses single quotes that break on Windows)
  • Secure: Avoids shell injection risks by not using shell=True
  • Robust: Handles paths with spaces without any quoting complexity
  • Respects shebangs: Scripts with #!/bin/bash are executed with the correct interpreter

Testing

Tested with a repo cloned to a path containing spaces:

/Users/.../Programming Projects/Hackathons/Cactus AI x Google Deepmind 2026/Resources/...

cactus build --python now completes successfully.

Added shlex.quote() to properly escape paths with spaces in run_command().
This fixes build failures when the cactus repo is cloned into a directory
path containing spaces (e.g., 'Programming Projects').

Signed-off-by: Adithya Narayanan <[email protected]>
Copilot AI review requested due to automatic review settings February 21, 2026 00:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes cactus build failures when the repository path contains spaces by adjusting how shell commands are constructed/executed in the CLI.

Changes:

  • Added shlex import.
  • Updated run_command() to shlex.quote() string commands before executing them via subprocess.run(..., shell=True).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Improved fix based on code review feedback:
- Removed shlex.quote() approach which has Windows compatibility issues
- Use subprocess.run with shell=False by converting string paths to lists
- This is more robust, secure, and cross-platform

The shell=False approach:
- Handles paths with spaces correctly without quoting
- Works on both Unix and Windows
- Avoids shell injection risks
- Respects script shebangs when execute bit is set

Signed-off-by: Adithya Narayanan <[email protected]>
@HenryNdubuaku
Copy link
Copy Markdown
Collaborator

Thanks so much for this @adithya-n05

@HenryNdubuaku HenryNdubuaku merged commit d1616c3 into cactus-compute:main Feb 23, 2026
1 check passed
ncylich pushed a commit that referenced this pull request Feb 24, 2026
* fix: handle spaces in paths when running shell commands

Added shlex.quote() to properly escape paths with spaces in run_command().
This fixes build failures when the cactus repo is cloned into a directory
path containing spaces (e.g., 'Programming Projects').

Signed-off-by: Adithya Narayanan <[email protected]>

* fix: use shell=False to handle spaces in paths safely

Improved fix based on code review feedback:
- Removed shlex.quote() approach which has Windows compatibility issues
- Use subprocess.run with shell=False by converting string paths to lists
- This is more robust, secure, and cross-platform

The shell=False approach:
- Handles paths with spaces correctly without quoting
- Works on both Unix and Windows
- Avoids shell injection risks
- Respects script shebangs when execute bit is set

Signed-off-by: Adithya Narayanan <[email protected]>

---------

Signed-off-by: Adithya Narayanan <[email protected]>
cattermelon1234 pushed a commit to cattermelon1234/cactus that referenced this pull request Feb 28, 2026
…te#377)

* fix: handle spaces in paths when running shell commands

Added shlex.quote() to properly escape paths with spaces in run_command().
This fixes build failures when the cactus repo is cloned into a directory
path containing spaces (e.g., 'Programming Projects').

Signed-off-by: Adithya Narayanan <[email protected]>

* fix: use shell=False to handle spaces in paths safely

Improved fix based on code review feedback:
- Removed shlex.quote() approach which has Windows compatibility issues
- Use subprocess.run with shell=False by converting string paths to lists
- This is more robust, secure, and cross-platform

The shell=False approach:
- Handles paths with spaces correctly without quoting
- Works on both Unix and Windows
- Avoids shell injection risks
- Respects script shebangs when execute bit is set

Signed-off-by: Adithya Narayanan <[email protected]>

---------

Signed-off-by: Adithya Narayanan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: cactus build fails when repo path contains spaces

3 participants