High severity beginner · Fix: 2-5 min

FileNotFoundError

modal.exception.FileNotFoundError

What this error means
Modal raises a FileNotFoundError when the specified volume mount path does not exist on the host or container environment.

Stack trace

traceback
FileNotFoundError: [Errno 2] No such file or directory: '/path/to/mount'
  at modal.volume.mount_path_check (/app/modal/volume.py:45)
  at modal.function.run (/app/modal/function.py:112)
  at main.py:23
QUICK FIX
Verify and create the exact absolute directory path on your host before deploying your Modal function with volume mounts.

Why it happens

Modal requires that any volume mount paths specified in the function or container configuration exist on the host machine or within the container environment. If the path is missing or incorrectly specified, Modal cannot mount the volume and raises this error.

Detection

Check your Modal function logs for FileNotFoundError mentioning the mount path. Validate volume paths exist locally before deployment to catch this early.

Causes & fixes

1

The host directory specified for volume mounting does not exist.

✓ Fix

Create the directory on your local machine or host environment before running the Modal function.

2

The volume mount path is misspelled or incorrectly specified in the Modal volume configuration.

✓ Fix

Double-check the mount path string in your Modal volume or function definition for typos or incorrect paths.

3

Using a relative path instead of an absolute path for the volume mount.

✓ Fix

Specify an absolute path for the volume mount to ensure Modal can locate the directory correctly.

4

The container environment does not have access permissions to the specified mount path.

✓ Fix

Ensure the container user has read/write permissions on the host directory being mounted.

Code: broken vs fixed

Broken - triggers the error
python
import modal

stub = modal.Stub()

@stub.function(
    mounts=[modal.Mount.from_local_dir("./data", remote_path="/app/data")]
)
def process():
    with open("/app/data/input.txt") as f:
        print(f.read())

# This will raise FileNotFoundError if './data' does not exist locally
process()
Fixed - works correctly
python
import os
import modal

os.makedirs("./data", exist_ok=True)  # Fixed: ensure local directory exists

stub = modal.Stub()

@stub.function(
    mounts=[modal.Mount.from_local_dir("./data", remote_path="/app/data")]
)
def process():
    with open("/app/data/input.txt") as f:
        print(f.read())

process()  # Now runs without FileNotFoundError
Added os.makedirs to create the local directory before mounting, ensuring the volume mount path exists and preventing FileNotFoundError.

Workaround

Wrap your Modal function call in a try/except FileNotFoundError block and log a clear error message prompting to create the missing directory before retrying.

Prevention

Always validate and create all local directories used for volume mounts before deploying Modal functions, and use absolute paths with correct permissions.

Python 3.9+ · modal >=0.1.0 · tested on 0.5.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.