{"record":{"id":"d2420eda04311aac","repo":"n8n-io/n8n","slug":"failed-to-write-file-filepath-result-stderr","errorCode":null,"errorMessage":"Failed to write file ${filePath}: ${result.stderr}","messagePattern":"Failed to write file (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/@n8n/instance-ai/src/workspace/sandbox-fs.ts","lineNumber":153,"sourceCode":" * Write a file in the sandbox via shell command.\n * Uses base64 encoding to safely transfer arbitrary content without\n * shell escaping issues (heredocs break on certain characters).\n * Creates parent directories automatically.\n */\nexport async function writeFileViaSandbox(\n\tworkspace: SandboxCommandTarget,\n\tfilePath: string,\n\tcontent: string | Buffer,\n\toptions?: SandboxIoRetryOptions,\n): Promise<void> {\n\tawait retryTransientSandboxIo(\n\t\tasync () => {\n\t\t\tconst runWriteCommand = async (command: string) => {\n\t\t\t\tconst result = await runInSandbox(workspace, command, {\n\t\t\t\t\tabortSignal: options?.abortSignal,\n\t\t\t\t});\n\t\t\t\tif (result.exitCode !== 0) {\n\t\t\t\t\tthrow new Error(`Failed to write file ${filePath}: ${result.stderr}`);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t// Ensure parent directory exists\n\t\t\tconst dir = filePath.substring(0, filePath.lastIndexOf('/'));\n\t\t\tif (dir) {\n\t\t\t\tawait runWriteCommand(`mkdir -p '${escapeSingleQuotes(dir)}'`);\n\t\t\t}\n\n\t\t\t// Encode content as base64, transfer it in small chunks, then decode in the sandbox.\n\t\t\t// Some providers run commands through spawn(), where a single huge argument can hit E2BIG.\n\t\t\tconst b64 =\n\t\t\t\ttypeof content === 'string'\n\t\t\t\t\t? Buffer.from(content, 'utf-8').toString('base64')\n\t\t\t\t\t: content.toString('base64');\n\t\t\tconst tempPath = `${filePath}.base64.tmp-${Date.now()}-${Math.random().toString(36).slice(2)}`;\n\t\t\tconst escapedTempPath = escapeSingleQuotes(tempPath);\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/n8n-io/n8n/blob/5ac6606e81f67bb9534255570cd4e86fd8101eee/packages/@n8n/instance-ai/src/workspace/sandbox-fs.ts#L135-L171","documentation":"Error \"Failed to write file ${filePath}: ${result.stderr}\" thrown in n8n-io/n8n.","triggerScenarios":"Thrown at packages/@n8n/instance-ai/src/workspace/sandbox-fs.ts:153 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ac6606e81f67bb9534255570cd4e86fd8101eee","analyzedAt":"2026-08-12T05:26:35.080Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}