diff --git a/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts b/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts index fbb1097f7..e768c7809 100644 --- a/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/agentflow/CustomFunction/CustomFunction.ts @@ -175,8 +175,7 @@ class CustomFunction_Agentflow implements INode { try { const response = await executeJavaScriptCode(javascriptFunction, sandbox, { libraries: ['axios'], - streamOutput, - timeout: 10000 + streamOutput }) let finalOutput = response diff --git a/packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts b/packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts index 1c1b3a26f..634a660cf 100644 --- a/packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts +++ b/packages/components/nodes/documentloaders/CustomDocumentLoader/CustomDocumentLoader.ts @@ -119,8 +119,7 @@ class CustomDocumentLoader_DocumentLoaders implements INode { try { const response = await executeJavaScriptCode(javascriptFunction, sandbox, { - libraries: ['axios'], - timeout: 10000 + libraries: ['axios'] }) if (output === 'document' && Array.isArray(response)) { diff --git a/packages/components/nodes/prompts/ChatPromptTemplate/ChatPromptTemplate.ts b/packages/components/nodes/prompts/ChatPromptTemplate/ChatPromptTemplate.ts index d4a7847ee..b1d1f6dd3 100644 --- a/packages/components/nodes/prompts/ChatPromptTemplate/ChatPromptTemplate.ts +++ b/packages/components/nodes/prompts/ChatPromptTemplate/ChatPromptTemplate.ts @@ -130,8 +130,7 @@ class ChatPromptTemplate_Prompts implements INode { try { const response = await executeJavaScriptCode(messageHistoryCode, sandbox, { - libraries: ['axios', '@langchain/core'], - timeout: 10000 + libraries: ['axios', '@langchain/core'] }) const parsedResponse = JSON.parse(response) diff --git a/packages/components/nodes/sequentialagents/Agent/Agent.ts b/packages/components/nodes/sequentialagents/Agent/Agent.ts index 94812c492..0933731f1 100644 --- a/packages/components/nodes/sequentialagents/Agent/Agent.ts +++ b/packages/components/nodes/sequentialagents/Agent/Agent.ts @@ -940,9 +940,7 @@ const getReturnOutput = async (nodeData: INodeData, input: string, options: ICom const sandbox = createCodeExecutionSandbox(input, variables, flow) try { - const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox) if (typeof response !== 'object') throw new Error('Return output must be an object') return response diff --git a/packages/components/nodes/sequentialagents/Condition/Condition.ts b/packages/components/nodes/sequentialagents/Condition/Condition.ts index 9ce4d6928..8cac63f61 100644 --- a/packages/components/nodes/sequentialagents/Condition/Condition.ts +++ b/packages/components/nodes/sequentialagents/Condition/Condition.ts @@ -282,9 +282,7 @@ const runCondition = async (nodeData: INodeData, input: string, options: ICommon const sandbox = createCodeExecutionSandbox(input, variables, flow) try { - const response = await executeJavaScriptCode(conditionFunction, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(conditionFunction, sandbox) if (typeof response !== 'string') throw new Error('Condition function must return a string') return response diff --git a/packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts b/packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts index 4aaf3b97d..fada09305 100644 --- a/packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts +++ b/packages/components/nodes/sequentialagents/ConditionAgent/ConditionAgent.ts @@ -549,9 +549,7 @@ const runCondition = async ( const sandbox = createCodeExecutionSandbox(input, variables, flow) try { - const response = await executeJavaScriptCode(conditionFunction, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(conditionFunction, sandbox) if (typeof response !== 'string') throw new Error('Condition function must return a string') return response diff --git a/packages/components/nodes/sequentialagents/CustomFunction/CustomFunction.ts b/packages/components/nodes/sequentialagents/CustomFunction/CustomFunction.ts index c104a74f9..c86edf0aa 100644 --- a/packages/components/nodes/sequentialagents/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/sequentialagents/CustomFunction/CustomFunction.ts @@ -166,9 +166,7 @@ class CustomFunction_SeqAgents implements INode { const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox) try { - const response = await executeJavaScriptCode(javascriptFunction, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(javascriptFunction, sandbox) if (returnValueAs === 'stateObj') { if (typeof response !== 'object') { diff --git a/packages/components/nodes/sequentialagents/ExecuteFlow/ExecuteFlow.ts b/packages/components/nodes/sequentialagents/ExecuteFlow/ExecuteFlow.ts index 6b46c05e6..c1bc2fbca 100644 --- a/packages/components/nodes/sequentialagents/ExecuteFlow/ExecuteFlow.ts +++ b/packages/components/nodes/sequentialagents/ExecuteFlow/ExecuteFlow.ts @@ -264,8 +264,7 @@ class ExecuteFlow_SeqAgents implements INode { try { let response = await executeJavaScriptCode(code, sandbox, { - useSandbox: false, - timeout: 10000 + useSandbox: false }) if (typeof response === 'object') { diff --git a/packages/components/nodes/sequentialagents/LLMNode/LLMNode.ts b/packages/components/nodes/sequentialagents/LLMNode/LLMNode.ts index f52fe2c87..e0b577fb2 100644 --- a/packages/components/nodes/sequentialagents/LLMNode/LLMNode.ts +++ b/packages/components/nodes/sequentialagents/LLMNode/LLMNode.ts @@ -712,9 +712,7 @@ const getReturnOutput = async (nodeData: INodeData, input: string, options: ICom const sandbox = createCodeExecutionSandbox(input, variables, flow) try { - const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox) if (typeof response !== 'object') throw new Error('Return output must be an object') return response diff --git a/packages/components/nodes/sequentialagents/State/State.ts b/packages/components/nodes/sequentialagents/State/State.ts index 01e07e6e8..1d22d7d84 100644 --- a/packages/components/nodes/sequentialagents/State/State.ts +++ b/packages/components/nodes/sequentialagents/State/State.ts @@ -204,9 +204,7 @@ class State_SeqAgents implements INode { const sandbox = createCodeExecutionSandbox('', variables, flow) try { - const response = await executeJavaScriptCode(`return ${stateMemoryCode}`, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(`return ${stateMemoryCode}`, sandbox) if (typeof response !== 'object') throw new Error('State must be an object') const returnOutput: ISeqAgentNode = { diff --git a/packages/components/nodes/sequentialagents/ToolNode/ToolNode.ts b/packages/components/nodes/sequentialagents/ToolNode/ToolNode.ts index 3c126793d..3475a2772 100644 --- a/packages/components/nodes/sequentialagents/ToolNode/ToolNode.ts +++ b/packages/components/nodes/sequentialagents/ToolNode/ToolNode.ts @@ -575,9 +575,7 @@ const getReturnOutput = async ( const sandbox = createCodeExecutionSandbox(input, variables, flow) try { - const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox) if (typeof response !== 'object') throw new Error('Return output must be an object') return response diff --git a/packages/components/nodes/sequentialagents/commonUtils.ts b/packages/components/nodes/sequentialagents/commonUtils.ts index 42456bc4f..302ce943b 100644 --- a/packages/components/nodes/sequentialagents/commonUtils.ts +++ b/packages/components/nodes/sequentialagents/commonUtils.ts @@ -396,9 +396,7 @@ export const checkMessageHistory = async ( const sandbox = createCodeExecutionSandbox('', variables, flow) try { - const response = await executeJavaScriptCode(messageHistory, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(messageHistory, sandbox) if (!Array.isArray(response)) throw new Error('Returned message history must be an array') if (sysPrompt) { diff --git a/packages/components/nodes/tools/AgentAsTool/AgentAsTool.ts b/packages/components/nodes/tools/AgentAsTool/AgentAsTool.ts index 8bb9c1595..fbf3965db 100644 --- a/packages/components/nodes/tools/AgentAsTool/AgentAsTool.ts +++ b/packages/components/nodes/tools/AgentAsTool/AgentAsTool.ts @@ -364,8 +364,7 @@ try { const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox) let response = await executeJavaScriptCode(code, sandbox, { - useSandbox: false, - timeout: 10000 + useSandbox: false }) if (typeof response === 'object') { diff --git a/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts b/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts index b42bf716b..b63d7b6af 100644 --- a/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts +++ b/packages/components/nodes/tools/ChatflowTool/ChatflowTool.ts @@ -372,8 +372,7 @@ try { const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox) let response = await executeJavaScriptCode(code, sandbox, { - useSandbox: false, - timeout: 10000 + useSandbox: false }) if (typeof response === 'object') { diff --git a/packages/components/nodes/tools/CustomTool/core.ts b/packages/components/nodes/tools/CustomTool/core.ts index 1301c01b4..9b899f765 100644 --- a/packages/components/nodes/tools/CustomTool/core.ts +++ b/packages/components/nodes/tools/CustomTool/core.ts @@ -124,9 +124,7 @@ export class DynamicStructuredTool< const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox) - let response = await executeJavaScriptCode(this.code, sandbox, { - timeout: 10000 - }) + let response = await executeJavaScriptCode(this.code, sandbox) if (typeof response === 'object') { response = JSON.stringify(response) diff --git a/packages/components/nodes/tools/OpenAPIToolkit/core.ts b/packages/components/nodes/tools/OpenAPIToolkit/core.ts index f4b3499da..5eb329fe9 100644 --- a/packages/components/nodes/tools/OpenAPIToolkit/core.ts +++ b/packages/components/nodes/tools/OpenAPIToolkit/core.ts @@ -253,9 +253,7 @@ export class DynamicStructuredTool< const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox) - let response = await executeJavaScriptCode(this.customCode || defaultCode, sandbox, { - timeout: 10000 - }) + let response = await executeJavaScriptCode(this.customCode || defaultCode, sandbox) if (typeof response === 'object') { response = JSON.stringify(response) diff --git a/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts b/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts index cfae8b6d3..d4cfd5d32 100644 --- a/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts +++ b/packages/components/nodes/utilities/CustomFunction/CustomFunction.ts @@ -132,9 +132,7 @@ class CustomFunction_Utilities implements INode { const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox) try { - const response = await executeJavaScriptCode(javascriptFunction, sandbox, { - timeout: 10000 - }) + const response = await executeJavaScriptCode(javascriptFunction, sandbox) if (typeof response === 'string' && !isEndingNode) { return handleEscapeCharacters(response, false) diff --git a/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts b/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts index f74395d3a..572762b32 100644 --- a/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts +++ b/packages/components/nodes/utilities/IfElseFunction/IfElseFunction.ts @@ -131,16 +131,12 @@ class IfElseFunction_Utilities implements INode { const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox) try { - const responseTrue = await executeJavaScriptCode(ifFunction, sandbox, { - timeout: 10000 - }) + const responseTrue = await executeJavaScriptCode(ifFunction, sandbox) if (responseTrue) return { output: typeof responseTrue === 'string' ? handleEscapeCharacters(responseTrue, false) : responseTrue, type: true } - const responseFalse = await executeJavaScriptCode(elseFunction, sandbox, { - timeout: 10000 - }) + const responseFalse = await executeJavaScriptCode(elseFunction, sandbox) return { output: typeof responseFalse === 'string' ? handleEscapeCharacters(responseFalse, false) : responseFalse, type: false } } catch (e) { diff --git a/packages/components/src/utils.ts b/packages/components/src/utils.ts index 05e4e418a..22b2b7cae 100644 --- a/packages/components/src/utils.ts +++ b/packages/components/src/utils.ts @@ -1439,6 +1439,10 @@ export const executeJavaScriptCode = async ( ): Promise => { const { timeout = 300000, useSandbox = true, streamOutput, libraries = [], nodeVMOptions = {} } = options const shouldUseSandbox = useSandbox && process.env.E2B_APIKEY + let timeoutMs = timeout + if (process.env.SANDBOX_TIMEOUT) { + timeoutMs = parseInt(process.env.SANDBOX_TIMEOUT, 10) + } if (shouldUseSandbox) { try { @@ -1495,7 +1499,7 @@ export const executeJavaScriptCode = async ( } } - const sbx = await Sandbox.create({ apiKey: process.env.E2B_APIKEY, timeoutMs: timeout }) + const sbx = await Sandbox.create({ apiKey: process.env.E2B_APIKEY, timeoutMs }) // Install libraries for (const library of libraries) { @@ -1554,7 +1558,7 @@ export const executeJavaScriptCode = async ( }, eval: false, wasm: false, - timeout + timeout: timeoutMs } // Merge with custom nodeVMOptions if provided