langchain-ai/deepagents · error · OSError
temporary artifact is not a regular file
Error message
temporary artifact is not a regular file
What it means
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).
Source
Thrown at libs/code/deepagents_code/auto_mode.py:1055
*,
thread_key: str,
turn_id: str,
tool_call_id: str,
) -> AutoTempArtifact:
data = content.encode("utf-8")
temp_root = Path(tempfile.gettempdir()).absolute()
file_descriptor, raw_path = tempfile.mkstemp(
prefix=_TEMP_ARTIFACT_PREFIX,
suffix=suffix,
dir=temp_root,
)
file_path = Path(raw_path)
complete = False
try:
file_stat = _write_temp_artifact_bytes(file_descriptor, data)
if not stat.S_ISREG(file_stat.st_mode):
msg = "temporary artifact is not a regular file"
raise OSError(msg)
getuid = getattr(os, "getuid", None)
if callable(getuid) and file_stat.st_uid != getuid():
msg = "temporary artifact is not owned by this user"
raise OSError(msg)
if os.name != "nt" and stat.S_IMODE(file_stat.st_mode) & 0o077:
msg = "temporary artifact permissions are too broad"
raise OSError(msg)
artifact = AutoTempArtifact(
allocation_id=uuid4().hex,
file_path=str(file_path),
thread_key=thread_key,
turn_id=turn_id,
created_by_tool_call_id=tool_call_id,
file_device=file_stat.st_dev,
file_inode=file_stat.st_ino,
)
complete = True
return artifactView on GitHub (pinned to a1af029e6e)
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
Defensive patterns
Strategy: validation
Validate before calling
import tempfile, stat, os real = getattr(tempfile, "__file__", "") assert "stdlib" in real or real.startswith(os.path.dirname(os.__file__)), "tempfile is shadowed" fd, p = tempfile.mkstemp(); st = os.fstat(fd); os.close(fd); os.unlink(p) assert stat.S_ISREG(st.st_mode), "mkstemp did not yield a regular file"
Try / catch
try:
artifact = create_temp_artifact(content=content, suffix="")
except OSError as exc:
if "not a regular file" in str(exc):
inspect_tempfile_module_and_tmpdir()
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- temporary artifact is not owned by this user
- temporary artifact permissions are too broad
- temporary artifact provenance is invalid
- temporary artifact identity changed
- Permission path must not contain '..': {path!r}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/c5264d9c1ae0000b.
Report an issue: GitHub.