{"record":{"id":"af23e64a832807b3","repo":"langchain-ai/deepagents","slug":"directory-is-owned-by-another-user-path","errorCode":null,"errorMessage":"Directory is owned by another user: {path}","messagePattern":"Directory is owned by another user: (.+?)","errorType":"exception","errorClass":"PermissionError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/offload.py","lineNumber":105,"sourceCode":"    root.\n\n    Args:\n        path: Directory to create and harden to `0o700`.\n\n    Raises:\n        OSError: If the path exists but is not a directory, or the directory\n            cannot be created or its mode changed (e.g. a read-only mount).\n        PermissionError: If the existing directory is owned by another local user.\n    \"\"\"\n    path.mkdir(mode=0o700, parents=True, exist_ok=True)\n    info = path.lstat()\n    if not stat.S_ISDIR(info.st_mode):\n        msg = f\"Path is not a directory: {path}\"\n        raise OSError(msg)\n    getuid = getattr(os, \"getuid\", None)\n    if getuid is not None and info.st_uid != getuid():\n        msg = f\"Directory is owned by another user: {path}\"\n        raise PermissionError(msg)\n    # `mkdir(mode=...)` does not tighten an existing directory. These directories\n    # can hold conversation data and offloaded tool results, so they must remain\n    # inaccessible to other local accounts regardless of the process umask.\n    path.chmod(0o700)\n\n\ndef _probe_writable(path: Path) -> None:\n    \"\"\"Confirm `path` accepts new files (catches read-only mounts).\n\n    Creating the directory is insufficient when it already exists on a read-only\n    mount; a temporary file proves writes can succeed.\n\n    Args:\n        path: Directory to probe.\n    \"\"\"\n    with tempfile.NamedTemporaryFile(dir=path, prefix=\".write-test-\"):\n        pass\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/offload.py#L87-L123","documentation":"`_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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reclaim ownership: `sudo chown -R \"$(id -u):$(id -g)\" <dir>`","Avoid running the tool with sudo; use a per-user data directory","In containers, run with the same UID as the volume owner or fix volume permissions"],"exampleFix":"# before\nPermissionError: Directory is owned by another user: ~/.deepagents/artifacts\n# after\nsudo chown -R \"$(id -u):$(id -g)\" ~/.deepagents","handlingStrategy":"try-catch","validationCode":"import os, stat\ninfo = path.lstat()\nif getattr(os, \"getuid\", None) and info.st_uid != os.getuid():\n    raise PermissionError(f\"{path} is owned by uid {info.st_uid}; run chown or use your own user\")","typeGuard":null,"tryCatchPattern":"try:\n    root = _prepare_temp_dir()\nexcept PermissionError as e:\n    logging.error(\"fix ownership: sudo chown -R $(id -u):$(id -g) %s\", path)\n    raise SystemExit(1)","preventionTips":["Don't run the tool under sudo; use per-user data directories","In containers, match the UID of the volume owner","After switching users, chown the state directory before rerunning"],"tags":["filesystem","permissions","offload","permission-error","ownership"],"backgroundTag":"permission-denied","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}