alibaba/spring-ai-alibaba · error · RuntimeException
code execution failed, exit code: {exitCode}, logs: {logs}
Error message
code execution failed, exit code: {exitCode}, logs: {logs} What it means
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.
Source
Thrown at spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/code/CodeExecutorNodeAction.java:100
TemplateTransformer templateTransformer = CODE_TEMPLATE_TRANSFORMERS.get(language);
if (templateTransformer == null) {
throw new RuntimeException("Unsupported language: " + language);
}
RunnerAndPreload runnerAndPreload = templateTransformer.transformCaller(code, inputs, style);
String response = executeCode(language, runnerAndPreload.preloadScript(), runnerAndPreload.runnerScript());
return templateTransformer.transformResponse(response);
}
private String executeCode(CodeLanguage language, String preloadScript, String code) throws Exception {
List<CodeBlock> codeBlockList = new ArrayList<>(10);
codeBlockList.add(new CodeBlock(CODE_LANGUAGE_TO_RUNNING_LANGUAGE.get(language), code));
CodeExecutionResult codeExecutionResult = codeExecutor.executeCodeBlocks(codeBlockList,
this.codeExecutionConfig);
if (codeExecutionResult.exitCode() != 0) {
throw new RuntimeException("code execution failed, exit code: " + codeExecutionResult.exitCode()
+ ", logs: " + codeExecutionResult.logs());
}
return codeExecutionResult.logs();
}
@Override
public Map<String, Object> apply(OverAllState state) throws Exception {
Map<String, Object> inputs = Optional.ofNullable(params)
.orElse(List.of())
.stream()
.collect(Collectors.toUnmodifiableMap(CodeParam::argName, param -> Optional.ofNullable(param.value())
.or(() -> StringUtils.hasText(param.stateKey()) ? state.value(param.stateKey()) : Optional.empty())
.orElseThrow(() -> new IllegalStateException("param has no value and legal key!"))));
Map<String, Object> resultObjectMap = executeWorkflowCodeTemplate(CodeLanguage.fromValue(codeLanguage), code,
inputs);
Map<String, Object> updatedState = new HashMap<>();
if (StringUtils.hasLength(this.outputKey)) {View on GitHub (pinned to f82da0b50f)
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
Defensive patterns
Strategy: try-catch
Validate before calling
// syntax-check generated code before execution where possible
Process p = new ProcessBuilder("python", "-m", "py_compile", scriptPath).start();
if (p.waitFor() != 0) throw new IllegalStateException("generated code fails to compile"); Try / catch
try { logs = action.call(state); } catch (RuntimeException e) { if (e.getMessage().startsWith("code execution failed")) { log.error(e.getMessage()); /* inspect logs */ } } Prevention
- 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
When it happens
Trigger: The executed code script crashes, raises an uncaught exception, or exits non-zero (syntax error, missing dependency in the sandbox, runtime exception) during executeCodeBlocks.
Common situations: 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.
Related errors
- Path: outside root directory:
- Path: outside root directory:
- Path outside root directory:
- Language not recognized in code execution:{language}
- Unsupported language: {language}
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/925150bb3f4ce99d.
Report an issue: GitHub.