FileNotFoundError
modal.exception.FileNotFoundError
Stack trace
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
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
The host directory specified for volume mounting does not exist.
Create the directory on your local machine or host environment before running the Modal function.
The volume mount path is misspelled or incorrectly specified in the Modal volume configuration.
Double-check the mount path string in your Modal volume or function definition for typos or incorrect paths.
Using a relative path instead of an absolute path for the volume mount.
Specify an absolute path for the volume mount to ensure Modal can locate the directory correctly.
The container environment does not have access permissions to the specified mount path.
Ensure the container user has read/write permissions on the host directory being mounted.
Code: broken vs fixed
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() 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 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.