{"record":{"id":"c5264d9c1ae0000b","repo":"langchain-ai/deepagents","slug":"temporary-artifact-is-not-a-regular-file","errorCode":null,"errorMessage":"temporary artifact is not a regular file","messagePattern":"temporary artifact is not a regular file","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/auto_mode.py","lineNumber":1055,"sourceCode":"    *,\n    thread_key: str,\n    turn_id: str,\n    tool_call_id: str,\n) -> AutoTempArtifact:\n    data = content.encode(\"utf-8\")\n    temp_root = Path(tempfile.gettempdir()).absolute()\n    file_descriptor, raw_path = tempfile.mkstemp(\n        prefix=_TEMP_ARTIFACT_PREFIX,\n        suffix=suffix,\n        dir=temp_root,\n    )\n    file_path = Path(raw_path)\n    complete = False\n    try:\n        file_stat = _write_temp_artifact_bytes(file_descriptor, data)\n        if not stat.S_ISREG(file_stat.st_mode):\n            msg = \"temporary artifact is not a regular file\"\n            raise OSError(msg)\n        getuid = getattr(os, \"getuid\", None)\n        if callable(getuid) and file_stat.st_uid != getuid():\n            msg = \"temporary artifact is not owned by this user\"\n            raise OSError(msg)\n        if os.name != \"nt\" and stat.S_IMODE(file_stat.st_mode) & 0o077:\n            msg = \"temporary artifact permissions are too broad\"\n            raise OSError(msg)\n        artifact = AutoTempArtifact(\n            allocation_id=uuid4().hex,\n            file_path=str(file_path),\n            thread_key=thread_key,\n            turn_id=turn_id,\n            created_by_tool_call_id=tool_call_id,\n            file_device=file_stat.st_dev,\n            file_inode=file_stat.st_ino,\n        )\n        complete = True\n        return artifact","sourceCodeStart":1037,"sourceCodeEnd":1073,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/auto_mode.py#L1037-L1073","documentation":"Raised by `_allocate_temp_artifact` after writing the temp file: `stat.S_ISREG(file_stat.st_mode)` is false, so the path returned by `tempfile.mkstemp` is not a regular file. The library verifies this defensively because a swapped `tempfile` module or a symlink/ATTACK on the temp directory could substitute a non-regular object (FIFO, socket, device).","triggerScenarios":"Calling `create_temp_artifact` (which calls `_allocate_temp_artifact`) when the `mkstemp` result lstats as a non-regular file — typically because `tempfile` was monkeypatched or shadowed, or the temp directory was replaced by something that hands back non-regular inodes.","commonSituations":"Test scaffolding or site-packages shadowing the stdlib `tempfile` module; unusual temp filesystems that report non-regular modes; security tooling that replaces temp files with FIFOs/devices to intercept writes.","solutions":["Verify the real stdlib `tempfile` is in use: `python -c \"import tempfile; print(tempfile.__file__)\"` — remove any shadowing `tempfile.py` or monkeypatch","Check that the temp directory (`tempfile.gettempdir()` / `$TMPDIR`) is on a normal filesystem that supports regular files","Inspect for security software or containers that substitute files in `/tmp` and switch to a different `TMPDIR`","If seen in tests, stop patching `tempfile.mkstemp` in a way that returns non-regular fd/path pairs"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import tempfile, stat, os\nreal = getattr(tempfile, \"__file__\", \"\")\nassert \"stdlib\" in real or real.startswith(os.path.dirname(os.__file__)), \"tempfile is shadowed\"\nfd, p = tempfile.mkstemp(); st = os.fstat(fd); os.close(fd); os.unlink(p)\nassert stat.S_ISREG(st.st_mode), \"mkstemp did not yield a regular file\"","typeGuard":null,"tryCatchPattern":"try:\n    artifact = create_temp_artifact(content=content, suffix=\"\")\nexcept OSError as exc:\n    if \"not a regular file\" in str(exc):\n        inspect_tempfile_module_and_tmpdir()\n    else:\n        raise","preventionTips":["Never name test files `tempfile.py` or patch `tempfile.mkstemp` to return exotic objects","Keep TMPDIR on a filesystem that supports regular files","Audit container images for security layers that rewrite temp files","Verify stdlib integrity if this fires outside tests"],"tags":["filesystem","temp-file","security","validation"],"backgroundTag":"temp-file-not-regular","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}