{"record":{"id":"925150bb3f4ce99d","repo":"alibaba/spring-ai-alibaba","slug":"code-execution-failed-exit-code-exitcode-logs","errorCode":null,"errorMessage":"code execution failed, exit code: {exitCode}, logs: {logs}","messagePattern":"code execution failed, exit code: (.+?), logs: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/code/CodeExecutorNodeAction.java","lineNumber":100,"sourceCode":"\t\tTemplateTransformer templateTransformer = CODE_TEMPLATE_TRANSFORMERS.get(language);\n\t\tif (templateTransformer == null) {\n\t\t\tthrow new RuntimeException(\"Unsupported language: \" + language);\n\t\t}\n\n\t\tRunnerAndPreload runnerAndPreload = templateTransformer.transformCaller(code, inputs, style);\n\t\tString response = executeCode(language, runnerAndPreload.preloadScript(), runnerAndPreload.runnerScript());\n\n\t\treturn templateTransformer.transformResponse(response);\n\t}\n\n\tprivate String executeCode(CodeLanguage language, String preloadScript, String code) throws Exception {\n\t\tList<CodeBlock> codeBlockList = new ArrayList<>(10);\n\t\tcodeBlockList.add(new CodeBlock(CODE_LANGUAGE_TO_RUNNING_LANGUAGE.get(language), code));\n\n\t\tCodeExecutionResult codeExecutionResult = codeExecutor.executeCodeBlocks(codeBlockList,\n\t\t\t\tthis.codeExecutionConfig);\n\t\tif (codeExecutionResult.exitCode() != 0) {\n\t\t\tthrow new RuntimeException(\"code execution failed, exit code: \" + codeExecutionResult.exitCode()\n\t\t\t\t\t+ \", logs: \" + codeExecutionResult.logs());\n\t\t}\n\n\t\treturn codeExecutionResult.logs();\n\t}\n\n\t@Override\n\tpublic Map<String, Object> apply(OverAllState state) throws Exception {\n\t\tMap<String, Object> inputs = Optional.ofNullable(params)\n\t\t\t.orElse(List.of())\n\t\t\t.stream()\n\t\t\t.collect(Collectors.toUnmodifiableMap(CodeParam::argName, param -> Optional.ofNullable(param.value())\n\t\t\t\t.or(() -> StringUtils.hasText(param.stateKey()) ? state.value(param.stateKey()) : Optional.empty())\n\t\t\t\t.orElseThrow(() -> new IllegalStateException(\"param has no value and legal key!\"))));\n\t\tMap<String, Object> resultObjectMap = executeWorkflowCodeTemplate(CodeLanguage.fromValue(codeLanguage), code,\n\t\t\t\tinputs);\n\t\tMap<String, Object> updatedState = new HashMap<>();\n\t\tif (StringUtils.hasLength(this.outputKey)) {","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/code/CodeExecutorNodeAction.java#L82-L118","documentation":"CodeExecutorNodeAction.executeCode runs the generated code blocks through the configured CodeExecutor and inspects the returned exit code. A non-zero exit code means the executed program failed, so it throws RuntimeException including the exit code and the captured execution logs. The logs in the message are the primary debugging surface.","triggerScenarios":"The executed code script crashes, raises an uncaught exception, or exits non-zero (syntax error, missing dependency in the sandbox, runtime exception) during executeCodeBlocks.","commonSituations":"Python/JS code raising exceptions due to bad inputs; missing packages in the execution sandbox; sandbox/resource limits killing the process; generated template code failing after variable substitution.","solutions":["Read the 'logs' portion of the message to find the actual runtime error and stack trace","Fix the bug in the code being executed (or its inputs)","Install required dependencies in the code-execution sandbox/image","Reproduce the script locally with the same inputs to iterate faster"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// syntax-check generated code before execution where possible\nProcess p = new ProcessBuilder(\"python\", \"-m\", \"py_compile\", scriptPath).start();\nif (p.waitFor() != 0) throw new IllegalStateException(\"generated code fails to compile\");","typeGuard":null,"tryCatchPattern":"try { logs = action.call(state); } catch (RuntimeException e) { if (e.getMessage().startsWith(\"code execution failed\")) { log.error(e.getMessage()); /* inspect logs */ } }","preventionTips":["Always read the logs embedded in the message first","Install required packages in the execution sandbox image","Dry-run generated code locally with the same inputs","Validate inputs to the code template to avoid substitution errors"],"tags":["code-execution","nonzero-exit","sandbox"],"backgroundTag":"command-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}