{"record":{"id":"c03a26ee9831bd4c","repo":"firecracker-microvm/firecracker","slug":"p-not-found-in-container-and-not-under-host-work","errorCode":null,"errorMessage":"{p} not found in container and not under host workspace {host_root}.","messagePattern":"(.+?) not found in container and not under host workspace (.+?)\\.","errorType":"exception","errorClass":"SystemExit","httpStatus":null,"severity":"error","filePath":"tools/sandbox.py","lineNumber":51,"sourceCode":"        \"GB\": 2**30,\n    }\n    match = re.match(r\"(?P<val>\\d+)(?P<unit>[MG]B)\", param.upper())\n    return int(match.group(\"val\")) * unit[match.group(\"unit\")]\n\n\ndef translate_host_path(p):\n    \"\"\"Rewrite a host path under HOST_FC_ROOT_DIR to its /firecracker/... equivalent.\"\"\"\n    if p is None:\n        return None\n    host_root = os.environ.get(\"HOST_FC_ROOT_DIR\")\n    if not host_root:\n        return Path(p)\n    p = Path(p).resolve()\n    if p.is_relative_to(host_root):\n        return FC_WORKSPACE_DIR / p.relative_to(host_root)\n    if p.exists():\n        return p\n    raise SystemExit(\n        f\"{p} not found in container and not under host workspace {host_root}.\"\n    )\n\n\ndef pick_default_rootfs(candidates):\n    \"\"\"Default to AL2023, falling back to Ubuntu, then any rootfs available.\"\"\"\n    if not candidates:\n        return None\n    for prefix in (\"amazonlinux-\", \"ubuntu-\"):\n        matches = [c for c in candidates if c.name.startswith(prefix)]\n        if matches:\n            return matches[-1]\n    return candidates[-1]\n\n\ndefault_rootfs = pick_default_rootfs(rootfs)\ndefault_kernel = kernels[-1] if kernels else None\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/firecracker-microvm/firecracker/blob/ea50487ec11602100b90ed63f85fe00bd30fbde8/tools/sandbox.py#L33-L69","documentation":"`translate_host_path` in tools/sandbox.py rewrites host paths into the container-visible /firecracker workspace. When the environment variable HOST_FC_ROOT_DIR is set (i.e. the sandbox runs inside the dev container), a path that is not relative to that host root AND does not exist at its resolved location cannot be mapped, so the script terminates via `raise SystemExit(...)`. This is a path-translation failure between host and container, not a Firecracker failure.","triggerScenarios":"Running `tools/sandbox.py` inside the container with HOST_FC_ROOT_DIR set, while passing `--kernel`, `--rootfs`, `--binary-dir`, or `--cpu-template-path` pointing to a host-only location (e.g. /home/me/vmlinux) that is neither bind-mounted into the container nor present at that resolved path. It also fires for typo'd paths, since only existing paths fall through the `p.exists()` branch.","commonSituations":"Developer builds in the containerized dev environment but references artifacts downloaded on the host outside the Firecracker checkout; the path exists on the host but was never bind-mounted; a relative path that resolves against a different cwd inside the container; a stale HOST_FC_ROOT_DIR pointing at an old checkout location.","solutions":["Copy or move the artifact (kernel, rootfs, cpu template) into the Firecracker workspace on the host so it lands under HOST_FC_ROOT_DIR and maps to /firecracker/... inside the container.","Verify the file actually exists at the exact path given (check for typos and for trailing characters); only existing paths are accepted outside the host root.","If you are running on the host rather than in the container, unset HOST_FC_ROOT_DIR so translate_host_path returns the path unchanged.","If the file lives elsewhere on the host, add it to the container's bind mounts / docker run -v so `p.exists()` succeeds inside the container."],"exampleFix":"# before (artifact outside the shared workspace, not mounted)\nHOST_FC_ROOT_DIR=/home/me/firecracker python3 tools/sandbox.py --cpu-template-path /home/me/templates/c3.json\n# SystemExit: /home/me/templates/c3.json not found in container and not under host workspace /home/me/firecracker.\n\n# after (artifact inside the workspace, maps to /firecracker/...)\ncp /home/me/templates/c3.json /home/me/firecracker/templates/c3.json\npython3 tools/sandbox.py --cpu-template-path /firecracker/templates/c3.json","handlingStrategy":"validation","validationCode":"import os\nfrom pathlib import Path\n\ndef translatable(p: str) -> bool:\n    \"\"\"True when sandbox.py will accept this path (mirrors translate_host_path).\"\"\"\n    if p is None:\n        return True\n    host_root = os.environ.get(\"HOST_FC_ROOT_DIR\")\n    if not host_root:\n        return True\n    q = Path(p).resolve()\n    return q.is_relative_to(host_root) or q.exists()\n\nassert translatable(args.cpu_template_path), (\n    f\"{args.cpu_template_path} is outside {os.environ.get('HOST_FC_ROOT_DIR')} \"\n    \"and does not exist inside the container\")","typeGuard":null,"tryCatchPattern":"try:\n    args.kernel = translate_host_path(args.kernel)\nexcept SystemExit as e:\n    print(f\"path translation failed: {e}\", file=sys.stderr)\n    print(\"put the artifact under the firecracker workspace or bind-mount it\", file=sys.stderr)\n    raise","preventionTips":["Keep all kernels/rootfs/templates inside the Firecracker checkout so they map into /firecracker automatically.","Bind-mount any host directory containing artifacts into the dev container before referencing it.","Run `ls <path>` (or Path(p).exists()) inside the same container before launching the sandbox.","Unset HOST_FC_ROOT_DIR when running the script directly on the host."],"tags":["python","dev-tooling","docker","paths","environment"],"backgroundTag":null,"analyzedSha":"ea50487ec11602100b90ed63f85fe00bd30fbde8","analyzedAt":"2026-08-16T11:52:35.093Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}