Comfy-Org/ComfyUI · error · Exception
**** ERROR: Saving image outside the output folder is not al
Error message
**** ERROR: Saving image outside the output folder is not allowed.\n full_output_folder: {full_output_folder}\n output_dir: {output_dir} What it means
get_save_image_path splits filename_prefix into subfolder + filename and joins them under output_dir; if the normalized prefix contains '../' components, full_output_folder resolves outside output_dir and is_within_directory fails. The node logs the error (paths included) and raises, preventing writes outside the designated output tree.
Source
Thrown at folder_paths.py:557
input = input.replace("%hour%", str(now.tm_hour).zfill(2))
input = input.replace("%minute%", str(now.tm_min).zfill(2))
input = input.replace("%second%", str(now.tm_sec).zfill(2))
return input
if "%" in filename_prefix:
filename_prefix = compute_vars(filename_prefix, image_width, image_height)
subfolder = os.path.dirname(os.path.normpath(filename_prefix))
filename = os.path.basename(os.path.normpath(filename_prefix))
full_output_folder = os.path.join(output_dir, subfolder)
if not is_within_directory(output_dir, full_output_folder):
err = "**** ERROR: Saving image outside the output folder is not allowed." + \
"\n full_output_folder: " + os.path.abspath(full_output_folder) + \
"\n output_dir: " + output_dir
logging.error(err)
raise Exception(err)
try:
counter = max(filter(lambda a: os.path.normcase(a[1][:-1]) == os.path.normcase(filename) and a[1][-1] == "_", map(map_filename, os.listdir(full_output_folder))))[0] + 1
except ValueError:
counter = 1
except FileNotFoundError:
os.makedirs(full_output_folder, exist_ok=True)
counter = 1
return full_output_folder, filename, counter, subfolder, filename_prefix
def get_input_subfolders() -> list[str]:
"""Returns a list of all subfolder paths in the input directory, recursively.
Returns:
List of folder paths relative to the input directory, excluding the root directory
"""
input_dir = get_input_directory()
folders = []View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Use a prefix with only subdirectory names (e.g. 'ComfyUI/myrun') relative to the output directory
- To change the output root, configure the server's output directory setting instead of traversing with '../'
- If automating, sanitize prefixes: strip '..' and absolute-path components before submission
Example fix
# before prefix = "../../shared/renders" # after prefix = "renders" # saved under <output_dir>/renders/
Defensive patterns
Strategy: validation
Validate before calling
import os n = os.path.normpath(filename_prefix) assert not os.path.isabs(n) and ".." not in n.split(os.sep), "prefix must stay inside the output dir"
Type guard
def is_safe_prefix(prefix: str) -> bool:
n = os.path.normpath(prefix)
return not os.path.isabs(n) and ".." not in n.split(os.sep) Prevention
- Use subfolder-style prefixes relative to the output directory only
- Change the server output_dir configuration instead of traversing with '../'
When it happens
Trigger: A SaveImage/SaveVideo filename_prefix like '../../tmp/out' that escapes the output directory; workflow JSON with traversal-style prefixes; API-submitted prompts with crafted prefixes.
Common situations: Users trying to save directly to an arbitrary absolute path via the prefix; copied workflows from setups where the prefix implied a different directory structure; security probing of the queue API.
Related errors
- destination escapes base directory
- Invalid folder name {folder_name!r}: resolves outside of {ba
- Invalid file path: {!r}
- Unknown user:
- System User prefix not allowed
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/911d10dc9ea24922.
Report an issue: GitHub.