diff --git a/src/mpsd_software_manager/mpsd_software.py b/src/mpsd_software_manager/mpsd_software.py
index 6cd8565164c6851d422452a48b41869377552b05..29dfd3eae9a106fe221439e47b619cdd19db45df 100755
--- a/src/mpsd_software_manager/mpsd_software.py
+++ b/src/mpsd_software_manager/mpsd_software.py
@@ -1213,7 +1213,7 @@ def remove_spack_environment(spack_dir, environment_name, build_log_path=None):
     ]
     build_log_path = build_log_path or "/dev/null"
     run(
-        " && ".join(commands_to_execute) + f" 2>&1 |tee {build_log_path}",
+        "(" + " && ".join(commands_to_execute) + f") 2>&1 |tee {build_log_path}",
         shell=True,
         check=True,
     )
@@ -1242,7 +1242,7 @@ def remove_spack_package(spack_dir, package, build_log_path=None):
         f"spack uninstall -y {package}",
     ]
     run(
-        " && ".join(commands_to_execute) + f" 2>&1 |tee {build_log_path}",
+        "(" + " && ".join(commands_to_execute) + f") 2>&1 |tee {build_log_path}",
         shell=True,
         check=True,
     )