langchain-ai/deepagents · critical · SystemExit

Could not import Deep Agents Code dependencies or locate dco

Error message

Could not import Deep Agents Code dependencies or locate dcode on PATH.

What it means

This is the fallback failure of `_ensure_runtime` in the thread-inspector script: after the script cannot import Deep Agents Code dependencies in the current interpreter AND re-execution attempts against candidates (dcode, deepagents-code, known venv paths) either found nothing on PATH or failed, it exits with this SystemExit message. In short: no usable Python runtime or `dcode` executable with the required dependencies could be found.

Source

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

                stderr=subprocess.DEVNULL,
                check=False,
                timeout=10,
            )
        except (subprocess.TimeoutExpired, OSError):
            # A hung or non-executable candidate must not abort the search;
            # skip it and fall through to the next one (or the clear error below).
            continue
        if check.returncode == 0:
            env = os.environ.copy()
            env["DEEPAGENTS_THREAD_INSPECTOR_REEXEC"] = "1"
            os.execve(  # noqa: S606  # Replaces this process with that interpreter.
                str(candidate),
                [str(candidate), str(Path(__file__).resolve()), *sys.argv[1:]],
                env,
            )

    msg = "Could not import Deep Agents Code dependencies or locate dcode on PATH."
    raise SystemExit(msg)


def _default_db_path() -> Path:
    """Return the sessions DB path dcode itself would use.

    Returns:
        The default sessions database path.

    Raises:
        SystemExit: If `DEEPAGENTS_HOME` is set to a value dcode rejects, so
            this script never reads a database dcode never writes.
    """
    explicit = os.environ.get("DEEPAGENTS_SESSIONS_DB")
    if explicit:
        return Path(explicit).expanduser()
    try:
        from deepagents_code._paths import get_deepagents_home  # noqa: PLC2701
    except ImportError:

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Install deepagents-code so `dcode` is on PATH (verify with `which dcode`), or run the script from within the project environment (`uv run`).
  2. Add the venv bin directory to PATH (e.g. `export PATH="$PWD/.venv/bin:$PATH"`) before invoking the script.
  3. Activate the correct virtualenv first (`source .venv/bin/activate`) so the direct import succeeds without re-exec.

Example fix

// before
$ /usr/bin/python3 scripts/inspect_sessions.py   # no deps, no dcode on PATH
// after
$ source .venv/bin/activate && python scripts/inspect_sessions.py  # or ensure dcode on PATH
Defensive patterns

Strategy: fallback

Validate before calling

import shutil, importlib.util
if importlib.util.find_spec('deepagents_code') is None and not (shutil.which('dcode') or shutil.which('deepagents-code')):
    import sys; sys.exit('Install deepagents-code or add dcode to PATH before running inspect_sessions.py')

Prevention

When it happens

Trigger: Running the script where (1) the current python cannot import deepagents_code, and (2) `shutil.which('dcode')` and `shutil.which('deepagents-code')` both return None (and no venv candidate works), so no re-exec target exists.

Common situations: Running the skill on a machine where dcode was never installed; a container/CI image with only the scripts copied but not the package; a PATH that excludes the venv's bin directory (e.g. cron, non-interactive shells).

Related errors


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