Skip to content

Commit 448548e

Browse files
waleedlatif1claude
andcommitted
fix(execute-command): cap timeout at MAX_DURATION, simplify error handler, document workingDirectory
- Enforce upper bound on timeout (MAX_DURATION - 10s) to prevent orphan processes - Remove unreachable throw branch in handler — always return structured data - Document that workingDirectory does not support variable references Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5782b68 commit 448548e

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

apps/sim/app/api/tools/execute-command/run/route.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,12 @@ export async function POST(req: NextRequest) {
333333
workflowId,
334334
} = body
335335

336+
const MAX_ALLOWED_TIMEOUT_MS = (MAX_DURATION - 10) * 1000
336337
const parsedTimeout = Number(body.timeout)
337-
const timeout = parsedTimeout > 0 ? parsedTimeout : DEFAULT_EXECUTION_TIMEOUT_MS
338+
const timeout = Math.min(
339+
parsedTimeout > 0 ? parsedTimeout : DEFAULT_EXECUTION_TIMEOUT_MS,
340+
MAX_ALLOWED_TIMEOUT_MS
341+
)
338342

339343
if (!command || typeof command !== 'string') {
340344
return NextResponse.json(

apps/sim/blocks/blocks/execute-command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const ExecuteCommandBlock: BlockConfig<ExecuteCommandOutput> = {
1616
- Chain multiple commands with && to run them sequentially.
1717
- Use <blockName.output> syntax to reference outputs from other blocks.
1818
- Use {{ENV_VAR}} syntax to reference environment variables.
19-
- The working directory defaults to the server process directory if not specified.
19+
- The working directory defaults to the server process directory if not specified. Variable references are not supported in the Working Directory field — use a literal path.
2020
- A non-zero exit code is returned as data (exitCode > 0), not treated as a workflow error. Use a Condition block to branch on exitCode if needed.
2121
- Variable values from other blocks are interpolated directly into the command string. Avoid passing untrusted user input as block references to prevent shell injection.
2222
`,

apps/sim/executor/handlers/execute-command/execute-command-handler.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,10 @@ export class ExecuteCommandBlockHandler implements BlockHandler {
4444
)
4545

4646
if (!result.success) {
47-
if (result.output) {
48-
return {
49-
...result.output,
50-
error: result.error || 'Command execution failed',
51-
}
47+
return {
48+
...(result.output ?? { stdout: '', stderr: '', exitCode: 1 }),
49+
error: result.error || 'Command execution failed',
5250
}
53-
throw new Error(result.error || 'Command execution failed')
5451
}
5552

5653
return { ...result.output, error: null }

0 commit comments

Comments
 (0)