{"record":{"id":"eb09bbf5048c2313","repo":"mastra-ai/mastra","slug":"git-missing","errorCode":"git-missing","errorMessage":"git is not installed in the sandbox. The sandbox template must include git.","messagePattern":"git is not installed in the sandbox\\. The sandbox template must include git\\.","errorType":"error_code","errorClass":"MaterializeError","httpStatus":null,"severity":"error","filePath":"mastracode/factory/src/integrations/github/sandbox.ts","lineNumber":257,"sourceCode":"  const repo = repoInfo.repoFullName;\n\n  // 0. Defense in depth: never build a git command from values that aren't\n  // strictly shaped, even if a malformed row reached the DB. Inputs are also\n  // validated at the route boundary before storage.\n  if (!/^[\\w.-]+\\/[\\w.-]+$/.test(repo)) {\n    throw new MaterializeError(`Refusing to materialize: invalid repo full name '${repo}'.`, 'clone-failed');\n  }\n  if (!/^[A-Za-z0-9_./-]+$/.test(repoInfo.defaultBranch)) {\n    throw new MaterializeError(\n      `Refusing to materialize: invalid default branch '${repoInfo.defaultBranch}'.`,\n      'clone-failed',\n    );\n  }\n\n  // 1. Preflight: git must be installed in the sandbox template.\n  const gitVersion = await sh(sandbox, 'git --version');\n  if (gitVersion.exitCode !== 0) {\n    throw new MaterializeError(\n      'git is not installed in the sandbox. The sandbox template must include git.',\n      'git-missing',\n    );\n  }\n\n  const authUrl = tokenUrl(repo, token);\n\n  // The DB's `materializedAt` can drift from disk in both directions: a fresh\n  // binding row over an already-populated workdir (local dev DB resets,\n  // repaired rows, earlier flows) must pull instead of failing `git clone` on\n  // the non-empty directory, and a stale `materializedAt` over an empty\n  // sandbox (an expired/recreated VM whose disk was wiped) must re-clone\n  // instead of running `git -C <workdir>` against a directory that no longer\n  // exists. Disk is the source of truth: detect the checkout instead of\n  // trusting the row.\n  const alreadyMaterialized = await hasExistingCheckout(sandbox, workdir, repo);\n\n  let tokenInRemote = false;","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/mastracode/factory/src/integrations/github/sandbox.ts#L239-L275","documentation":"As a preflight step, materializeRepo runs `git --version` inside the sandbox; a non-zero exit means the sandbox image lacks git, so materialization cannot proceed and throws this MaterializeError with code git-missing. The library requires the sandbox template to include git as part of its contract.","triggerScenarios":"materializeRepo() invoked against a sandbox created from a template/image that doesn't install git (minimal distro images, custom Dockerfiles without `apt-get install git`, broken PATH in the sandbox).","commonSituations":"Switching to a slimmer sandbox base image for cost/speed, a template regression after a Dockerfile refactor, or an offline/air-gapped sandbox where git was stripped.","solutions":["Add git to the sandbox template image (e.g. `apt-get update && apt-get install -y git` or the alpine equivalent) and rebuild.","Verify inside the sandbox with `git --version` to confirm PATH resolves correctly.","Pin to a sandbox template known to include git (the one the library is normally paired with).","If git was intentionally removed, restore it — no fallback clone path exists."],"exampleFix":"// before (Dockerfile)\nFROM node:22-slim\n// after\nFROM node:22-slim\nRUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*","handlingStrategy":"validation","validationCode":"const probe = await sh(sandbox, 'git --version');\nif (probe.exitCode !== 0) throw new Error('sandbox template is missing git; rebuild the image before materializing');","typeGuard":null,"tryCatchPattern":"try {\n  await materializeRepo(options);\n} catch (err) {\n  if (err instanceof MaterializeError && err.code === 'git-missing') {\n    throw new Error(`Sandbox template '${sandboxRow.templateId}' lacks git. Rebuild the image with git installed.`, { cause: err });\n  }\n  throw err;\n}","preventionTips":["Include git in every sandbox template Dockerfile and assert it in the image build CI.","Run a post-build smoke check (`git --version`) on sandbox images.","Pin sandbox templates so slimmed images can't silently drop git.","Document git as a hard requirement of the sandbox contract."],"tags":["environment","git","sandbox","missing-dependency"],"backgroundTag":"missing-dependency","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}