{"record":{"id":"a57c08c3a8a939b2","repo":"Hmbown/CodeWhale","slug":"docker-exec-container-exited-r-code-r-stderr-trim-slice-0","errorCode":null,"errorMessage":"docker exec ${container} exited ${r.code}: ${r.stderr.trim().slice(0, 400)}","messagePattern":"docker exec (.+?) exited (.+?): (.+?)","errorType":"exception","errorClass":"ExecError","httpStatus":null,"severity":"error","filePath":"crates/tui/plugins/computer-use/src/transport.mjs","lineNumber":259,"sourceCode":" */\nexport function dockerExec(computer, binding) {\n  const container = safeRemotePath(computer.container);\n  const remoteAgent = \"/app/docker/agent-exec.sh\";\n  const ex = {\n    kind: \"docker\",\n    container,\n    remoteAgent,\n    run(cmd, args = [], opts = {}) {\n      // Local side commands (docker itself) run directly.\n      return run(cmd, args, opts);\n    },\n    async remote(request, opts = {}) {\n      const r = await run(\"docker\", [\"exec\", container, \"/bin/sh\", remoteAgent, b64({ args: request.args ?? {}, tool: request.tool, nonce: crypto.randomBytes(6).toString(\"hex\") })], {\n        timeoutMs: opts.timeoutMs ?? 25_000,\n      });\n      if (r.aborted) throw Object.assign(new ExecError(\"computer request cancelled\", r), { code: \"cancelled\" });\n      if (r.timedOut) throw new ExecError(`docker exec ${container}: timed out`, r);\n      if (r.code !== 0) throw new ExecError(`docker exec ${container} exited ${r.code}: ${r.stderr.trim().slice(0, 400)}`, r);\n      const line = r.stdout.trim().split(\"\\n\").filter((l) => l.startsWith(\"{\")).pop();\n      const reply = line ? JSON.parse(line) : null;\n      if (!reply) throw new ExecError(`docker exec ${container}: agent returned no JSON receipt`, r);\n      return reply;\n    },\n  };\n  attachPersistentChannel(ex, binding, [\"docker\", \"exec\", \"-i\", container, \"/bin/sh\", remoteAgent, \"--serve\"]);\n  return ex;\n}\n\n/** Push the self-contained remote agent + src tree to an ssh computer. */\nexport async function installRemoteAgent(computer) {\n  const ex = sshExec(computer);\n  const srcDir = path.join(PLUGIN_ROOT, \"src\");\n  const rels = [\"agent.mjs\"];\n  for (const dir of [\"\", \"backends\"]) {\n    const full = path.join(srcDir, dir);\n    for (const f of fs.readdirSync(full)) {","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/tui/plugins/computer-use/src/transport.mjs#L241-L277","documentation":"The Docker transport throws this ExecError when `docker exec` exits with a nonzero status; the first 400 characters of stderr are embedded for diagnosis. It means the docker invocation itself failed — container, path, or agent problems — before any receipt could be returned.","triggerScenarios":"executor.remote() on docker transport with r.code !== 0: container not running, /bin/sh or remoteAgent path missing inside the container, agent crashed with nonzero exit, docker daemon permission errors.","commonSituations":"Container stopped/exited since registration; agent not installed in the container; image lacking node or /bin/sh (distroless images); docker permission denied for the current user (not in docker group).","solutions":["Check container state: docker ps -a | grep <container> and restart it if stopped","Verify the agent is installed inside the container at the expected path","Confirm the image contains /bin/sh and node: docker exec <container> /bin/sh -c 'node --version'","Read the stderr embedded in the error for the specific docker/agent failure","Re-run the agent installation step for docker transports"],"exampleFix":"// before\nawait ex.remote({ tool: \"platform\" }); // container stopped\n// after\nawait run(\"docker\", [\"start\", container]);\nawait ex.remote({ tool: \"platform\" });","handlingStrategy":"try-catch","validationCode":"const st = await run(\"docker\", [\"inspect\", \"-f\", \"{{.State.Running}}\", container]);\nif (st.code !== 0 || st.stdout.trim() !== \"true\") throw new Error(`container ${container} not running`);","typeGuard":"function isDockerExitError(e) { return e instanceof ExecError && /docker exec .* exited \\d+:/.test(e.message); }","tryCatchPattern":"try {\n  return await ex.remote(request, opts);\n} catch (e) {\n  if (/docker exec .* exited \\d+:/.test(e.message)) {\n    console.error(\"docker exec failed:\", e.message); // embedded stderr names the cause\n    // e.g. restart container or reinstall agent, then retry\n  }\n  throw e;\n}","preventionTips":["Ensure the container stays running between registrations","Install the agent in the image or via the docker install path before use","Use an image that includes /bin/sh and node (not distroless)","Keep the current user in the docker group to avoid permission exits"],"tags":["docker","remote-execution","process-exit"],"backgroundTag":"command-exited-nonzero","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}