From 8e83939ee89977b4309e89c216efcb391a95a9e4 Mon Sep 17 00:00:00 2001 From: Nicole Rappe Date: Fri, 3 Oct 2025 18:31:07 -0600 Subject: [PATCH] Ensure script wrapper sets process environment --- Data/Agent/Roles/role_ScriptExec_CURRENTUSER.py | 7 ++++++- Data/Agent/Roles/role_ScriptExec_SYSTEM.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Data/Agent/Roles/role_ScriptExec_CURRENTUSER.py b/Data/Agent/Roles/role_ScriptExec_CURRENTUSER.py index f9049e6..5195fd7 100644 --- a/Data/Agent/Roles/role_ScriptExec_CURRENTUSER.py +++ b/Data/Agent/Roles/role_ScriptExec_CURRENTUSER.py @@ -74,7 +74,12 @@ def _build_wrapped_script(content: str, env_map: Dict[str, str], timeout_seconds for key, value in (env_map or {}).items(): if not key: continue - inner_lines.append(f"$Env:{key} = {_ps_literal(value)}") + value_literal = _ps_literal(value) + key_literal = _ps_literal(key) + inner_lines.append( + f"[System.Environment]::SetEnvironmentVariable({key_literal}, {value_literal}, 'Process')" + ) + inner_lines.append(f"$Env:{key} = {value_literal}") inner_lines.append(content or "") inner = "\n".join(line for line in inner_lines if line is not None) script_block = "$__BorealisScript = {\n" + inner + "\n}\n" diff --git a/Data/Agent/Roles/role_ScriptExec_SYSTEM.py b/Data/Agent/Roles/role_ScriptExec_SYSTEM.py index 0ba5852..de45cc2 100644 --- a/Data/Agent/Roles/role_ScriptExec_SYSTEM.py +++ b/Data/Agent/Roles/role_ScriptExec_SYSTEM.py @@ -76,7 +76,12 @@ def _build_wrapped_script(content: str, env_map: Dict[str, str], timeout_seconds for key, value in (env_map or {}).items(): if not key: continue - inner_lines.append(f"$Env:{key} = {_ps_literal(value)}") + value_literal = _ps_literal(value) + key_literal = _ps_literal(key) + inner_lines.append( + f"[System.Environment]::SetEnvironmentVariable({key_literal}, {value_literal}, 'Process')" + ) + inner_lines.append(f"$Env:{key} = {value_literal}") inner_lines.append(content or "") inner = "\n".join(line for line in inner_lines if line is not None) script_block = "$__BorealisScript = {\n" + inner + "\n}\n"