langchain-ai/deepagents · error · PermissionError

Directory is owned by another user: {path}

Error message

Directory is owned by another user: {path}

What it means

`_harden_dir` checks the directory owner via `os.getuid()` and raises `PermissionError` if the directory is owned by a different local user. Since these directories hold conversation data and offloaded tool results, they must not be readable/writable by other accounts; this typically means a previous run under a different user (root, another account, a container) created them.

Source

Thrown at libs/code/deepagents_code/offload.py:105

    root.

    Args:
        path: Directory to create and harden to `0o700`.

    Raises:
        OSError: If the path exists but is not a directory, or the directory
            cannot be created or its mode changed (e.g. a read-only mount).
        PermissionError: If the existing directory is owned by another local user.
    """
    path.mkdir(mode=0o700, parents=True, exist_ok=True)
    info = path.lstat()
    if not stat.S_ISDIR(info.st_mode):
        msg = f"Path is not a directory: {path}"
        raise OSError(msg)
    getuid = getattr(os, "getuid", None)
    if getuid is not None and info.st_uid != getuid():
        msg = f"Directory is owned by another user: {path}"
        raise PermissionError(msg)
    # `mkdir(mode=...)` does not tighten an existing directory. These directories
    # can hold conversation data and offloaded tool results, so they must remain
    # inaccessible to other local accounts regardless of the process umask.
    path.chmod(0o700)


def _probe_writable(path: Path) -> None:
    """Confirm `path` accepts new files (catches read-only mounts).

    Creating the directory is insufficient when it already exists on a read-only
    mount; a temporary file proves writes can succeed.

    Args:
        path: Directory to probe.
    """
    with tempfile.NamedTemporaryFile(dir=path, prefix=".write-test-"):
        pass

View on GitHub (pinned to a1af029e6e)

Solutions

  1. Reclaim ownership: `sudo chown -R "$(id -u):$(id -g)" <dir>`
  2. Avoid running the tool with sudo; use a per-user data directory
  3. In containers, run with the same UID as the volume owner or fix volume permissions

Example fix

# before
PermissionError: Directory is owned by another user: ~/.deepagents/artifacts
# after
sudo chown -R "$(id -u):$(id -g)" ~/.deepagents
Defensive patterns

Strategy: try-catch

Validate before calling

import os, stat
info = path.lstat()
if getattr(os, "getuid", None) and info.st_uid != os.getuid():
    raise PermissionError(f"{path} is owned by uid {info.st_uid}; run chown or use your own user")

Try / catch

try:
    root = _prepare_temp_dir()
except PermissionError as e:
    logging.error("fix ownership: sudo chown -R $(id -u):$(id -g) %s", path)
    raise SystemExit(1)

Prevention

When it happens

Trigger: Running the app after a `sudo` invocation or a container first created the artifacts/user/temp directory as root, so `st_uid != getuid()` when the normal user runs again.

Common situations: Mixed sudo/non-sudo usage on the same home or cache directory; Docker volume created by root then used by a host user; CI writing the dir as one UID and local dev as another.

Understand the failure class

Background: Permission denied / not authorized / 403 Forbidden: access-control rejections when the caller lacks the required role, grant, or ownership — this error's family across 18 libraries.

Related errors


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