{"record":{"id":"e7009a66a293190f","repo":"google-gemini/gemini-cli","slug":"failed-to-query-lxc-container-containername","errorCode":null,"errorMessage":"Failed to query LXC container '${containerName}': ${err instanceof Error ? err.message : String(err)}. Make sure LXC/LXD is installed and '${containerName}' container exists. Create one with: lxc launch ubuntu:24.04 ${containerName}","messagePattern":"Failed to query LXC container '(.+?)': (.+?)\\. Make sure LXC/LXD is installed and '(.+?)' container exists\\. Create one with: lxc launch ubuntu:24\\.04 (.+?)","errorType":"exception","errorClass":"FatalSandboxError","httpStatus":null,"severity":"error","filePath":"packages/cli/src/utils/sandbox.ts","lineNumber":925,"sourceCode":"): Promise<number> {\n  const containerName = config.image || 'gemini-sandbox';\n  const workdir = path.resolve(process.cwd());\n\n  debugLogger.log(\n    `starting lxc sandbox (container: ${containerName}, workdir: ${workdir}) ...`,\n  );\n\n  // Verify the container exists and is running.\n  let listOutput: string;\n  try {\n    const { stdout } = await execFileAsync('lxc', [\n      'list',\n      containerName,\n      '--format=json',\n    ]);\n    listOutput = stdout.trim();\n  } catch (err) {\n    throw new FatalSandboxError(\n      `Failed to query LXC container '${containerName}': ${err instanceof Error ? err.message : String(err)}. ` +\n        `Make sure LXC/LXD is installed and '${containerName}' container exists. ` +\n        `Create one with: lxc launch ubuntu:24.04 ${containerName}`,\n    );\n  }\n\n  let containers: Array<{ name: string; status: string }> = [];\n  try {\n    const parsed: unknown = JSON.parse(listOutput);\n    if (Array.isArray(parsed)) {\n      containers = parsed\n        .filter(\n          (item): item is Record<string, unknown> =>\n            item !== null &&\n            typeof item === 'object' &&\n            'name' in item &&\n            'status' in item,\n        )","sourceCodeStart":907,"sourceCodeEnd":943,"githubUrl":"https://github.com/google-gemini/gemini-cli/blob/5024443c7217464a66e98f80d73172a26440bd8f/packages/cli/src/utils/sandbox.ts#L907-L943","documentation":"Thrown when the `lxc list <containerName> --format=json` command fails entirely (the execFileAsync call rejects). This indicates LXC/LXD tooling is not installed, not on PATH, the daemon (lxd) is not running, or the user lacks permission to invoke lxc. The message embeds the underlying error and a remediation command.","triggerScenarios":"execFileAsync('lxc', ['list', containerName, '--format=json']) rejects — lxc binary missing, lxd daemon not initialized (`lxd init` not run), snap permission issue, or LXC not installed at all.","commonSituations":"Fresh OS install without LXD. User installed LXC but not LXD, or vice versa. snap-based lxc requires the user to be in the lxd group or to use `sudo`. lxd daemon stopped. Wrong sandbox backend selected (LXC) when Docker was intended.","solutions":["Install LXD and initialize: `sudo apt install lxd && lxd init` (or `snap install lxd`).","Confirm `lxc list` works as your user; add yourself to the lxd group if needed (`sudo usermod -aG lxd $USER` then re-login).","Create the expected container: `lxc launch ubuntu:24.04 <containerName>`.","If you did not intend to use the LXC backend, switch the sandbox configuration to Docker/podman."],"exampleFix":"// before: LXC backend selected but lxd not installed\n// config.sandboxType = 'lxc'\n\n// after: install + create container\n// sudo snap install lxd\n// lxd init --auto\n// lxc launch ubuntu:24.04 gemini-sandbox","handlingStrategy":"validation","validationCode":"const { execSync } = require('child_process');\nfunction ensureLxcAvailable() {\n  try {\n    execSync('lxc --version', {stdio:'pipe'});\n    execSync('lxc list --format=json', {stdio:'pipe'});\n  } catch {\n    throw new Error('LXC/LXD not available. Install lxd (`sudo snap install lxd`) and run `lxd init`.');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await runLxcSandbox(config);\n} catch (e) {\n  if (e instanceof FatalSandboxError && /Failed to query LXC container/.test(e.message)) {\n    // guide the user to install LXD or switch backend\n  } else throw e;\n}","preventionTips":["Add an environment preflight that checks `lxc --version` before selecting the LXC backend.","Ensure the running user has lxd permissions."],"tags":["sandbox","lxc","lxd","installation","permissions"],"backgroundTag":null,"analyzedSha":"5024443c7217464a66e98f80d73172a26440bd8f","analyzedAt":"2026-08-12T06:01:53.711Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}