langchain-ai/deepagents · error · ExternalEditorError

External editor executable or temporary file was not found

Error message

External editor executable or temporary file was not found

What it means

While opening the external editor, Python raised `FileNotFoundError` — either the editor executable was not on PATH, or the temporary markdown file could not be created or found. With `raise_on_error=True` this is re-raised as `ExternalEditorError` with this message, chained to the original exception (`raise ... from exc`).

Source

Thrown at libs/code/deepagents_code/editor.py:192

        edited = Path(tmp_path).read_text(encoding="utf-8")

        # Normalize line endings
        edited = edited.replace("\r\n", "\n").replace("\r", "\n")

        # Most editors append a final newline on save (POSIX convention).
        # Strip exactly one so the cursor lands on content, not a blank line,
        # while preserving any intentional trailing newlines the user added.
        edited = edited.removesuffix("\n")

        # Chat composition historically treats a blank result as cancellation;
        # callers with their own submit-time validation may opt in to preserving it.
        if not allow_empty and not edited.strip():
            return None

    except FileNotFoundError as exc:
        if raise_on_error:
            msg = "External editor executable or temporary file was not found"
            raise ExternalEditorError(msg) from exc
        return None
    except Exception as exc:
        logger.warning("Editor failed", exc_info=True)
        if raise_on_error:
            msg = "External editor failed"
            raise ExternalEditorError(msg) from exc
        return None
    else:
        return edited
    finally:
        if tmp_path is not None:
            with contextlib.suppress(OSError):
                Path(tmp_path).unlink(missing_ok=True)

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Confirm the editor executable exists and is on PATH (`which <editor>`), or configure an absolute path.
  2. Check that your temp directory (`$TMPDIR`/`/tmp`) exists and is writable.
  3. Inspect `exc.__cause__` to see whether the editor binary or the temp file was missing.
  4. If the environment cannot be fixed, catch `ExternalEditorError` and fall back to an in-app editing path.

Example fix

// before
"editor": "code"  # not on PATH in server context
// after
"editor": "/usr/local/bin/code"
Defensive patterns

Strategy: try-catch

Validate before calling

import os, shutil, tempfile

def editor_ready() -> bool:
    editor = os.environ.get("EDITOR", "")
    return (
        bool(editor)
        and shutil.which(editor) is not None
        and os.path.isdir(tempfile.gettempdir())
    )

Try / catch

try:
    edited = open_in_editor(text, raise_on_error=True)
except ExternalEditorError as exc:
    logger.error("Editor launch failed: %r (cause: %r)", exc, exc.__cause__)
    edited = None

Prevention

When it happens

Trigger: `open_in_editor(raise_on_error=True)` where the resolved editor binary is missing from PATH, or the `NamedTemporaryFile`/filesystem interaction raises `FileNotFoundError` (e.g. deleted TMPDIR, unmounted tmpfs).

Common situations: Editor configured by name that only exists in an interactive shell's PATH (dotfiles not loaded); editor uninstalled after configuration; containers missing a temp directory; sandboxed environments blocking /tmp access.

Related errors


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