From 33433b1149bacbf93190e39627a324319c37056f Mon Sep 17 00:00:00 2001 From: Siddharth Ganesan Date: Mon, 6 Apr 2026 14:07:56 -0700 Subject: [PATCH] Fix shell var injection --- apps/sim/app/api/function/execute/route.ts | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/sim/app/api/function/execute/route.ts b/apps/sim/app/api/function/execute/route.ts index bd796105c6..2328bf11fb 100644 --- a/apps/sim/app/api/function/execute/route.ts +++ b/apps/sim/app/api/function/execute/route.ts @@ -739,18 +739,25 @@ export async function POST(req: NextRequest) { const lang = isValidCodeLanguage(language) ? language : DEFAULT_CODE_LANGUAGE - const codeResolution = resolveCodeVariables( - code, - executionParams, - envVars, - blockData, - blockNameMapping, - blockOutputSchemas, - workflowVariables, - lang - ) - resolvedCode = codeResolution.resolvedCode - const contextVariables = codeResolution.contextVariables + let contextVariables: Record = {} + if (lang === CodeLanguage.Shell) { + // For shell, env vars are injected as OS env vars via shellEnvs. + // Replace {{VAR}} placeholders with $VAR so the shell can access them natively. + resolvedCode = code.replace(/\{\{([A-Za-z_][A-Za-z0-9_]*)\}\}/g, '$$$1') + } else { + const codeResolution = resolveCodeVariables( + code, + executionParams, + envVars, + blockData, + blockNameMapping, + blockOutputSchemas, + workflowVariables, + lang + ) + resolvedCode = codeResolution.resolvedCode + contextVariables = codeResolution.contextVariables + } let jsImports = '' let jsRemainingCode = resolvedCode