langchain-ai/deepagents · critical · SystemExit

The selected Python runtime does not contain Deep Agents Cod

Error message

The selected Python runtime does not contain Deep Agents Code dependencies.

What it means

The thread-inspector script re-executes itself with a Python that has Deep Agents Code dependencies installed; if the re-executed runtime still cannot import them, the loop guard `DEEPAGENTS_THREAD_INSPECTOR_REEXEC=1` is set and `_ensure_runtime` aborts with this SystemExit message instead of retrying forever. It means the selected interpreter is missing the required packages (or `dcode`/`deepagents-code` cannot be located on PATH as a fallback).

Source

Thrown at libs/code/deepagents_code/built_in_skills/deepagents-thread-inspector/scripts/inspect_sessions.py:50

def _has_runtime() -> bool:
    try:
        for module, symbol in _RUNTIME_IMPORTS:
            getattr(importlib.import_module(module), symbol)
    except (AttributeError, ImportError):
        return False
    return True


def _ensure_runtime() -> None:
    if _has_runtime():
        return
    if os.environ.get("DEEPAGENTS_THREAD_INSPECTOR_REEXEC") == "1":
        msg = (
            "The selected Python runtime does not contain Deep Agents Code "
            "dependencies."
        )
        raise SystemExit(msg)

    candidates: list[Path] = []
    for command in ("dcode", "deepagents-code"):
        executable = shutil.which(command)
        if not executable:
            continue
        launcher = Path(executable).resolve()
        try:
            first_line = launcher.read_text(encoding="utf-8").splitlines()[0]
        except (OSError, UnicodeDecodeError, IndexError):
            first_line = ""
        if first_line.startswith("#!"):
            candidates.append(Path(first_line[2:].strip()))
        candidates.extend((launcher.parent / "python", launcher.parent / "python3"))

    seen: set[str] = set()
    for candidate in candidates:
        candidate_key = str(candidate.absolute())

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Install Deep Agents Code into the active environment (e.g. `uv pip install -e libs/code` or `pip install deepagents-code`).
  2. Check that `which dcode` / `which deepagents-code` points to a working installation; fix or remove a broken shim.
  3. Run the script via the `dcode`-managed environment (e.g. `uv run dcode` context) rather than a bare interpreter.
  4. Clear the stale `DEEPAGENTS_THREAD_INSPECTOR_REEXEC` env var if it leaked into the shell and masks a fresh attempt.

Example fix

// before
$ python scripts/inspect_sessions.py --thread abc   # bare system python, no deps
// after
$ uv run python scripts/inspect_sessions.py --thread abc  # or: dcode python scripts/inspect_sessions.py ...
Defensive patterns

Strategy: fallback

Validate before calling

import importlib.util
if importlib.util.find_spec('deepagents_code') is None:
    import sys; sys.exit('Run via dcode/uv environment: dcode python scripts/inspect_sessions.py')

Prevention

When it happens

Trigger: Running `inspect_sessions.py` in an environment where the current Python lacks deepagents-code, the script re-execs via a candidate found on PATH (dcode/deepagents-code) or venv, but the re-executed interpreter still cannot import the dependencies — detected via the `DEEPAGENTS_THREAD_INSPECTOR_REEXEC=1` env var.

Common situations: A broken or stale `dcode` shim on PATH pointing to an environment without dependencies; running with `uv run` or a bare system python whose site-packages lacks the package; a partially uninstalled/moved virtualenv.

Related errors


AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29). Data as JSON: /api/errors/3a03a0da371e56b7. Report an issue: GitHub.