reflex-dev/reflex · error · SystemExit
Failed to create temp directory for download: {ose}
Error message
Failed to create temp directory for download: {ose} What it means
Raised by `create_config_init_app_from_remote_template` when `tempfile.mkdtemp()` fails with an OSError while preparing a scratch directory for the template zip download. The `raise SystemExit(1) from None` aborts the `reflex init` flow; the underlying OSError text is included in the log line.
Source
Thrown at reflex/utils/templates.py:132
def create_config_init_app_from_remote_template(app_name: str, template_url: str):
"""Create new rxconfig and initialize app using a remote template.
Args:
app_name: The name of the app.
template_url: The path to the template source code as a zip file.
Raises:
SystemExit: If any download, file operations fail or unexpected zip file format.
"""
import httpx
# Create a temp directory for the zip download.
try:
temp_dir = tempfile.mkdtemp()
except OSError as ose:
logger.error(f"Failed to create temp directory for download: {ose}")
raise SystemExit(1) from None
# Use httpx GET with redirects to download the zip file.
zip_file_path: Path = Path(temp_dir) / "template.zip"
try:
# Note: following redirects can be risky. We only allow this for reflex built templates at the moment.
response = net.get(template_url, follow_redirects=True)
logger.debug(f"Server responded download request: {response}")
response.raise_for_status()
except httpx.HTTPError as he:
logger.error(f"Failed to download the template: {he}")
raise SystemExit(1) from None
try:
zip_file_path.write_bytes(response.content)
logger.debug(f"Downloaded the zip to {zip_file_path}")
except OSError as ose:
logger.error(f"Unable to write the downloaded zip to disk {ose}")
raise SystemExit(1) from None
View on GitHub (pinned to 45b8ed5ab7)
Solutions
- Check disk space (df -h) and free space if the temp volume is full.
- Verify TMPDIR is set to an existing, writable directory, or set it explicitly: TMPDIR=$HOME/tmp reflex init.
- If in a container, ensure /tmp is mounted writable.
Example fix
# no code fix; environment fix # before: TMPDIR=/nonexistent reflex init --template-url ... # after: mkdir -p $HOME/tmp && TMPDIR=$HOME/tmp reflex init --template-url ...
Defensive patterns
Strategy: fallback
Validate before calling
import os, tempfile
def temp_writable() -> bool:
try:
tempfile.mkdtemp()
return True
except OSError:
return False
# or pre-flight: os.access(os.environ.get("TMPDIR", "/tmp"), os.W_OK) Try / catch
try:
create_config_init_app_from_remote_template(...)
except SystemExit:
# inspect logs; retry with TMPDIR pointed at a writable location
os.environ["TMPDIR"] = os.path.expanduser("~/tmp")
create_config_init_app_from_remote_template(...) Prevention
- Pre-check disk space and TMPDIR writability in CI before running reflex init.
- Mount /tmp as writable tmpfs with adequate size in containers.
- Set TMPDIR explicitly in constrained environments.
When it happens
Trigger: Creating a new app from a remote template (reflex init with a template URL) on a system where the temp directory (TMPDIR/TMP/TEMP or /tmp) is unwritable, full, or missing; mkdtemp raising PermissionError/NoSpaceError (subclasses of OSError).
Common situations: Read-only or full /tmp in containers and CI; TMPDIR pointing to a nonexistent directory; sandboxed environments restricting filesystem writes; disk quota exceeded.
Related errors
- Failed to create temp directory for extracting zip: {ose}
- Unable to write the downloaded zip to disk {ose}
- Only {template_name=} should be provided, got {template_code
- For `{template_name}` template, `template_code_dir_name` and
- Failed to download the template: {he}
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/2d38cea2fdf01161.
Report an issue: GitHub.