langchain-ai/deepagents · error · SystemExit

dcode: {message}

Error message

dcode: {message}

What it means

`deepagents_code.__getattr__` provides `cli_main` lazily; if importing `deepagents_code.main` raises `DeepAgentsHomeError` (the dcode home/profile directory could not be resolved), it returns a stub `cli_main` that prints `dcode: {message}` to stderr and exits with status 2 instead of a traceback. The message names the actual home-resolution problem to fix.

Source

Thrown at libs/code/deepagents_code/__init__.py:56

    Note:
        Any import error other than an unresolvable profile location
        propagates unchanged; `DeepAgentsHomeError` is reported as a message
        plus exit 2 instead of a traceback.
    """
    if name == "cli_main":
        try:
            from deepagents_code.main import cli_main
        except DeepAgentsHomeError as exc:
            # `_paths` resolves the profile at import, so a bad DEEPAGENTS_HOME
            # or an unresolvable home surfaces here. Report it as a message
            # rather than a traceback: the user has a value to fix, and every
            # module that imports `_paths` would fail the same way.
            message = str(exc)

            def cli_main() -> None:
                print(f"dcode: {message}", file=sys.stderr)  # noqa: T201
                raise SystemExit(2)

        return cli_main
    msg = f"module {__name__!r} has no attribute {name!r}"
    raise AttributeError(msg)

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Read the message after `dcode:` — it names the exact home-resolution failure; fix that path or permission
  2. Unset or correct the `DEEPAGENTS_HOME` environment variable (or set it to a writable directory) and retry
  3. Verify the target directory exists and is writable by the current user (`mkdir -p <dir> && touch <dir>/.write-test`)
  4. In CI/containers, ensure a writable HOME or an explicit valid DEEPAGENTS_HOME is provided

Example fix

# before
DEEPAGENTS_HOME=/nonexistent/path dcode
# after
export DEEPAGENTS_HOME="$HOME/.dcode"
mkdir -p "$DEEPAGENTS_HOME"
dcode
Defensive patterns

Strategy: try-catch

Validate before calling

import os
home = os.environ.get("DEEPAGENTS_HOME", os.path.expanduser("~/.dcode"))
if not os.path.isdir(home) or not os.access(home, os.W_OK):
    os.makedirs(home, exist_ok=True)  # or fix DEEPAGENTS_HOME before launching

Try / catch

# shell level: capture exit code 2 and the `dcode:` message
if ! out=$(dcode 2>&1); then
  if [[ $out == dcode:* ]]; then echo "$out"; fi
fi

Prevention

When it happens

Trigger: Running the `dcode`/`deepagents-code` entry point when `DEEPAGENTS_HOME` points somewhere invalid/unusable, or `_paths` cannot resolve a home directory during import of `deepagents_code.main`.

Common situations: `DEEPAGENTS_HOME` set to a non-writable or nonexistent path in shell profile or CI; a read-only container filesystem; a typo'd env var value; running under a user whose HOME is unset.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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