leave default timeout for sandbox execution
This commit is contained in:
parent
dd284e37c3
commit
c10d91725e
|
|
@ -175,8 +175,7 @@ class CustomFunction_Agentflow implements INode {
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(javascriptFunction, sandbox, {
|
const response = await executeJavaScriptCode(javascriptFunction, sandbox, {
|
||||||
libraries: ['axios'],
|
libraries: ['axios'],
|
||||||
streamOutput,
|
streamOutput
|
||||||
timeout: 10000
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let finalOutput = response
|
let finalOutput = response
|
||||||
|
|
|
||||||
|
|
@ -119,8 +119,7 @@ class CustomDocumentLoader_DocumentLoaders implements INode {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(javascriptFunction, sandbox, {
|
const response = await executeJavaScriptCode(javascriptFunction, sandbox, {
|
||||||
libraries: ['axios'],
|
libraries: ['axios']
|
||||||
timeout: 10000
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (output === 'document' && Array.isArray(response)) {
|
if (output === 'document' && Array.isArray(response)) {
|
||||||
|
|
|
||||||
|
|
@ -130,8 +130,7 @@ class ChatPromptTemplate_Prompts implements INode {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(messageHistoryCode, sandbox, {
|
const response = await executeJavaScriptCode(messageHistoryCode, sandbox, {
|
||||||
libraries: ['axios', '@langchain/core'],
|
libraries: ['axios', '@langchain/core']
|
||||||
timeout: 10000
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const parsedResponse = JSON.parse(response)
|
const parsedResponse = JSON.parse(response)
|
||||||
|
|
|
||||||
|
|
@ -940,9 +940,7 @@ const getReturnOutput = async (nodeData: INodeData, input: string, options: ICom
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox, {
|
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response !== 'object') throw new Error('Return output must be an object')
|
if (typeof response !== 'object') throw new Error('Return output must be an object')
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
|
|
@ -282,9 +282,7 @@ const runCondition = async (nodeData: INodeData, input: string, options: ICommon
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(conditionFunction, sandbox, {
|
const response = await executeJavaScriptCode(conditionFunction, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response !== 'string') throw new Error('Condition function must return a string')
|
if (typeof response !== 'string') throw new Error('Condition function must return a string')
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
|
|
@ -549,9 +549,7 @@ const runCondition = async (
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(conditionFunction, sandbox, {
|
const response = await executeJavaScriptCode(conditionFunction, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response !== 'string') throw new Error('Condition function must return a string')
|
if (typeof response !== 'string') throw new Error('Condition function must return a string')
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
|
|
@ -166,9 +166,7 @@ class CustomFunction_SeqAgents implements INode {
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(javascriptFunction, sandbox, {
|
const response = await executeJavaScriptCode(javascriptFunction, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (returnValueAs === 'stateObj') {
|
if (returnValueAs === 'stateObj') {
|
||||||
if (typeof response !== 'object') {
|
if (typeof response !== 'object') {
|
||||||
|
|
|
||||||
|
|
@ -264,8 +264,7 @@ class ExecuteFlow_SeqAgents implements INode {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let response = await executeJavaScriptCode(code, sandbox, {
|
let response = await executeJavaScriptCode(code, sandbox, {
|
||||||
useSandbox: false,
|
useSandbox: false
|
||||||
timeout: 10000
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (typeof response === 'object') {
|
if (typeof response === 'object') {
|
||||||
|
|
|
||||||
|
|
@ -712,9 +712,7 @@ const getReturnOutput = async (nodeData: INodeData, input: string, options: ICom
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox, {
|
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response !== 'object') throw new Error('Return output must be an object')
|
if (typeof response !== 'object') throw new Error('Return output must be an object')
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
|
|
@ -204,9 +204,7 @@ class State_SeqAgents implements INode {
|
||||||
const sandbox = createCodeExecutionSandbox('', variables, flow)
|
const sandbox = createCodeExecutionSandbox('', variables, flow)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(`return ${stateMemoryCode}`, sandbox, {
|
const response = await executeJavaScriptCode(`return ${stateMemoryCode}`, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response !== 'object') throw new Error('State must be an object')
|
if (typeof response !== 'object') throw new Error('State must be an object')
|
||||||
const returnOutput: ISeqAgentNode = {
|
const returnOutput: ISeqAgentNode = {
|
||||||
|
|
|
||||||
|
|
@ -575,9 +575,7 @@ const getReturnOutput = async (
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox, {
|
const response = await executeJavaScriptCode(updateStateMemoryCode, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response !== 'object') throw new Error('Return output must be an object')
|
if (typeof response !== 'object') throw new Error('Return output must be an object')
|
||||||
return response
|
return response
|
||||||
|
|
|
||||||
|
|
@ -396,9 +396,7 @@ export const checkMessageHistory = async (
|
||||||
const sandbox = createCodeExecutionSandbox('', variables, flow)
|
const sandbox = createCodeExecutionSandbox('', variables, flow)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(messageHistory, sandbox, {
|
const response = await executeJavaScriptCode(messageHistory, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!Array.isArray(response)) throw new Error('Returned message history must be an array')
|
if (!Array.isArray(response)) throw new Error('Returned message history must be an array')
|
||||||
if (sysPrompt) {
|
if (sysPrompt) {
|
||||||
|
|
|
||||||
|
|
@ -364,8 +364,7 @@ try {
|
||||||
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
|
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
|
||||||
|
|
||||||
let response = await executeJavaScriptCode(code, sandbox, {
|
let response = await executeJavaScriptCode(code, sandbox, {
|
||||||
useSandbox: false,
|
useSandbox: false
|
||||||
timeout: 10000
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (typeof response === 'object') {
|
if (typeof response === 'object') {
|
||||||
|
|
|
||||||
|
|
@ -372,8 +372,7 @@ try {
|
||||||
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
|
const sandbox = createCodeExecutionSandbox('', [], {}, additionalSandbox)
|
||||||
|
|
||||||
let response = await executeJavaScriptCode(code, sandbox, {
|
let response = await executeJavaScriptCode(code, sandbox, {
|
||||||
useSandbox: false,
|
useSandbox: false
|
||||||
timeout: 10000
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (typeof response === 'object') {
|
if (typeof response === 'object') {
|
||||||
|
|
|
||||||
|
|
@ -124,9 +124,7 @@ export class DynamicStructuredTool<
|
||||||
|
|
||||||
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox)
|
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox)
|
||||||
|
|
||||||
let response = await executeJavaScriptCode(this.code, sandbox, {
|
let response = await executeJavaScriptCode(this.code, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response === 'object') {
|
if (typeof response === 'object') {
|
||||||
response = JSON.stringify(response)
|
response = JSON.stringify(response)
|
||||||
|
|
|
||||||
|
|
@ -253,9 +253,7 @@ export class DynamicStructuredTool<
|
||||||
|
|
||||||
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox)
|
const sandbox = createCodeExecutionSandbox('', this.variables || [], flow, additionalSandbox)
|
||||||
|
|
||||||
let response = await executeJavaScriptCode(this.customCode || defaultCode, sandbox, {
|
let response = await executeJavaScriptCode(this.customCode || defaultCode, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response === 'object') {
|
if (typeof response === 'object') {
|
||||||
response = JSON.stringify(response)
|
response = JSON.stringify(response)
|
||||||
|
|
|
||||||
|
|
@ -132,9 +132,7 @@ class CustomFunction_Utilities implements INode {
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await executeJavaScriptCode(javascriptFunction, sandbox, {
|
const response = await executeJavaScriptCode(javascriptFunction, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (typeof response === 'string' && !isEndingNode) {
|
if (typeof response === 'string' && !isEndingNode) {
|
||||||
return handleEscapeCharacters(response, false)
|
return handleEscapeCharacters(response, false)
|
||||||
|
|
|
||||||
|
|
@ -131,16 +131,12 @@ class IfElseFunction_Utilities implements INode {
|
||||||
const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)
|
const sandbox = createCodeExecutionSandbox(input, variables, flow, additionalSandbox)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const responseTrue = await executeJavaScriptCode(ifFunction, sandbox, {
|
const responseTrue = await executeJavaScriptCode(ifFunction, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
if (responseTrue)
|
if (responseTrue)
|
||||||
return { output: typeof responseTrue === 'string' ? handleEscapeCharacters(responseTrue, false) : responseTrue, type: true }
|
return { output: typeof responseTrue === 'string' ? handleEscapeCharacters(responseTrue, false) : responseTrue, type: true }
|
||||||
|
|
||||||
const responseFalse = await executeJavaScriptCode(elseFunction, sandbox, {
|
const responseFalse = await executeJavaScriptCode(elseFunction, sandbox)
|
||||||
timeout: 10000
|
|
||||||
})
|
|
||||||
|
|
||||||
return { output: typeof responseFalse === 'string' ? handleEscapeCharacters(responseFalse, false) : responseFalse, type: false }
|
return { output: typeof responseFalse === 'string' ? handleEscapeCharacters(responseFalse, false) : responseFalse, type: false }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
||||||
|
|
@ -1439,6 +1439,10 @@ export const executeJavaScriptCode = async (
|
||||||
): Promise<any> => {
|
): Promise<any> => {
|
||||||
const { timeout = 300000, useSandbox = true, streamOutput, libraries = [], nodeVMOptions = {} } = options
|
const { timeout = 300000, useSandbox = true, streamOutput, libraries = [], nodeVMOptions = {} } = options
|
||||||
const shouldUseSandbox = useSandbox && process.env.E2B_APIKEY
|
const shouldUseSandbox = useSandbox && process.env.E2B_APIKEY
|
||||||
|
let timeoutMs = timeout
|
||||||
|
if (process.env.SANDBOX_TIMEOUT) {
|
||||||
|
timeoutMs = parseInt(process.env.SANDBOX_TIMEOUT, 10)
|
||||||
|
}
|
||||||
|
|
||||||
if (shouldUseSandbox) {
|
if (shouldUseSandbox) {
|
||||||
try {
|
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
|
// Install libraries
|
||||||
for (const library of libraries) {
|
for (const library of libraries) {
|
||||||
|
|
@ -1554,7 +1558,7 @@ export const executeJavaScriptCode = async (
|
||||||
},
|
},
|
||||||
eval: false,
|
eval: false,
|
||||||
wasm: false,
|
wasm: false,
|
||||||
timeout
|
timeout: timeoutMs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge with custom nodeVMOptions if provided
|
// Merge with custom nodeVMOptions if provided
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue