alibaba/spring-ai-alibaba · error · RuntimeException
Error executing code in Docker container: {e.getMessage()}
Error message
Error executing code in Docker container: {e.getMessage()} What it means
DockerCodeExecutor.executeCodeBlocks wraps any exception raised while running code blocks inside a Docker container into a RuntimeException, preserving the original cause. This is a catch-all around Docker client calls, file mounts, and command execution, so the message text is generic and the real reason is always in the cause chain.
Source
Thrown at spring-boot-starters/spring-ai-alibaba-starter-builtin-nodes/src/main/java/com/alibaba/cloud/ai/graph/node/code/DockerCodeExecutor.java:183
}
finally {
// Clean up container
dockerClient.removeContainerCmd(container.getId()).withForce(true).exec();
// Delete temporary file
FileUtils.deleteFile(codeExecutionConfig.getWorkDir(), filename);
// Delete JAR files if language is Java
if ("java".equals(language)) {
FileUtils.deleteResourceJarFromWorkDir(hostWorkDir);
}
}
}
return new CodeExecutionResult(0, allLogs.toString());
}
catch (Exception e) {
logger.error("Error executing code in Docker container", e);
throw new RuntimeException("Error executing code in Docker container: " + e.getMessage(), e);
}
}
@Override
public void restart() {
}
private static class LogContainerResultCallback extends ResultCallbackTemplate<LogContainerResultCallback, Frame> {
private final StringBuilder log = new StringBuilder();
@Override
public void onNext(Frame frame) {
log.append(new String(frame.getPayload()));
}
@OverrideView on GitHub (pinned to f82da0b50f)
Solutions
- Read the wrapped cause (e.getCause()) in logs — logger.error already prints it — and fix the underlying Docker issue (start daemon, fix image, fix permissions).
- Verify Docker is reachable: run 'docker ps' with the same user that runs the JVM.
- Confirm the configured image exists locally or is pullable ('docker pull <image>').
- If Docker is unavailable, switch to LocalCommandlineCodeExecutor as the executor implementation.
Example fix
// before
codeExecutor.executeCodeBlocks(blocks, config); // RuntimeException with generic message
// after
try {
codeExecutor.executeCodeBlocks(blocks, config);
} catch (RuntimeException e) {
Throwable root = e.getCause();
log.error("Docker execution failed: {}", root == null ? e : root.getMessage());
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
Process p = new ProcessBuilder("docker", "info").start();
if (p.waitFor(10, TimeUnit.SECONDS) && p.exitValue() != 0) {
throw new IllegalStateException("Docker daemon unreachable");
} Try / catch
try {
result = dockerExecutor.executeCodeBlocks(blocks, config);
} catch (RuntimeException e) {
Throwable cause = e.getCause();
log.error("Docker code execution failed: {}", cause == null ? e.getMessage() : cause.getMessage(), cause);
throw new IllegalStateException("Code execution unavailable: " + (cause == null ? "unknown" : cause.getMessage()), e);
} Prevention
- Health-check the Docker daemon at application startup
- Run 'docker ps' under the same OS user as the JVM to catch permission issues
- Pre-pull the configured image and pin a version tag
- Provide a local executor fallback when Docker is unavailable
When it happens
Trigger: Calling executeCodeBlocks (directly or via a CodeExecutionNode) when: the Docker daemon is not running or unreachable, the Docker image cannot be pulled, the bind mount / work directory cannot be created, or the container command exits abnormally and the client throws.
Common situations: Docker Desktop not started on the dev machine; user not in the docker group (permission denied on /var/run/docker.sock); image name typo or private registry requiring auth; running inside CI without Docker-in-Docker; out-of-disk causing mount failures.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- ${response.getResult()}
- Async tool execution failed
- RuntimeException wrapping transaction failure (no literal me
- Language not recognized in code execution:{language}
- Failed to delete JAR files from working directory
AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09).
Data as JSON: /api/errors/64a1449c3b974e66.
Report an issue: GitHub.