Skip to content
Latchkey

Python "PermissionError: [Errno 13] Permission denied" in CI

PermissionError: [Errno 13] Permission denied is raised when the OS refuses an open, write, or execute because the current user lacks the required permission on the path.

What this error means

A step fails with "PermissionError: [Errno 13] Permission denied: '/var/lib/app/cache'" when opening, writing, or executing a path.

python
PermissionError: [Errno 13] Permission denied: '/var/lib/app/data.db'

Common causes

Writing to a directory owned by another user

A system path or a volume created by a different UID is not writable by the CI user.

Executing a file without the execute bit

A script was checked out without +x and the code tried to run it directly.

How to fix it

Write to a writable location or fix the mode

  1. Point output at a path the CI user owns, such as the workspace or a tmp dir.
  2. Add the execute bit (chmod +x) to scripts that must run directly.
  3. If a step must touch a protected path, run it with the right user or adjust ownership in setup.
Python
import tempfile, pathlib
out = pathlib.Path(tempfile.gettempdir()) / "app-cache"
out.mkdir(parents=True, exist_ok=True)

How to prevent it

  • Default to workspace- or tmp-relative paths for writes.
  • Track the execute bit on scripts in git.
  • Avoid hard-coding root-owned system paths.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →