{"record":{"id":"37c40253d61d80ed","repo":"JuliusBrussee/caveman","slug":"caveman-code-host-command-shell-is-not-available","errorCode":null,"errorMessage":"caveman-code: host command shell is not available","messagePattern":"caveman-code: host command shell is not available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/agent/src/code.ts","lineNumber":316,"sourceCode":"      `Times out after ${BASH_TIMEOUT_MS} ms; output is capped at ${caps.bash} bytes.`,\n    input: schema.object({\n      command: schema.string(),\n      timeoutMs: schema.optional(schema.integer()),\n    }),\n    effect: \"external\",\n    result: \"inline\",\n    timeoutMs: BASH_TIMEOUT_MS,\n    async execute(input, signal) {\n      const timeoutMs = Math.min(input.timeoutMs ?? BASH_TIMEOUT_MS, BASH_TIMEOUT_MS);\n      const shell = hostShellInvocation(input.command, process.platform, buildCodingProcessEnv());\n      const run = await runProcess(\n        shell.command,\n        shell.args,\n        await workspaceRoot(),\n        timeoutMs,\n        signal,\n      );\n      if (run.spawnFailed) throw new Error(\"caveman-code: host command shell is not available\");\n      const body = [\n        `exit ${run.timedOut ? `timeout after ${timeoutMs}ms` : run.code}`,\n        run.output.trim() === \"\" ? \"(no output)\" : run.output,\n      ].join(\"\\n\");\n      const text = capOutput(body, caps.bash);\n      record(`bash:${input.command.slice(0, 60)}`, text);\n      return text;\n    },\n  });\n\n  const editTool = tool({\n    name: \"edit_file\",\n    description:\n      \"Replace an exact string in a workspace file. The old string must appear exactly \" +\n      \"once unless replace_all is set. Writes to disk.\",\n    input: schema.object({\n      path: schema.string(),\n      old_string: schema.string(),","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/agent/src/code.ts#L298-L334","documentation":"The bash/host-command tool in packages/agent/src/code.ts runs the requested shell command via runProcess inside the workspace root with a timeout. If the shell process cannot be spawned at all (spawnFailed), it throws 'caveman-code: host command shell is not available' — the environment provides no usable shell executable.","triggerScenarios":"Invoking the bash tool on a host where /bin/sh or the configured shell binary is missing (distroless images, scratch containers), or spawning fails due to PATH issues, missing execute permission, or a sandbox that blocks process creation.","commonSituations":"Running the agent in a scratch/distroless container without a shell; hardened sandboxes (seccomp/AppArmor) blocking exec; misconfigured PATH after customizing the runtime environment; shell removed for hardening in CI images.","solutions":["Install or restore a shell in the runtime image (e.g. RUN apt-get install -y bash or apk add bash).","Ensure the shell binary is on the PATH visible to the agent process.","Check sandbox/seccomp policies allow process spawning (fork/exec) for the agent.","Run the agent from a standard base image (node:22-slim, debian-slim) rather than scratch/distroless.","Avoid shell-dependent tools in environments where process execution is intentionally disabled."],"exampleFix":"# before\nFROM scratch\n# after\nFROM debian:bookworm-slim  # provides /bin/sh","handlingStrategy":"validation","validationCode":"const { execFileSync } = require(\"child_process\");\ntry { execFileSync(\"/bin/sh\", [\"-c\", \"true\"], { stdio: \"ignore\" }); }\ncatch { throw new Error(\"No usable shell in this environment\"); }","typeGuard":null,"tryCatchPattern":"try {\n  await bash({ command });\n} catch (e) {\n  if (e.message.includes(\"host command shell is not available\")) {\n    console.error(\"Runtime image has no shell; use an image with /bin/sh or disable shell tools.\");\n  } else throw e;\n}","preventionTips":["Use a base image that ships a shell (debian/alpine-based, not scratch/distroless).","Confirm sandbox policies permit fork/exec before enabling shell tools.","Smoke-test process spawning (`/bin/sh -c true`) in container startup checks.","Keep the shell binary on the PATH visible to the agent process."],"tags":["shell","environment","process"],"backgroundTag":"command-not-found","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}