Run ComfyUI on the cloud for free with Modal's $30 monthly credits
Features โข Quick Start โข Installation โข Volume Setup โข Download Models โข Usage โข Contributing
Modal ร ComfyUI is a powerful solution that brings ComfyUIโa node-based UI for Stable Diffusion and other diffusion modelsโto the cloud, completely free. Leveraging Modal.com's generous $30 monthly credits, you can run advanced AI image generation workflows without managing expensive hardware or local GPU resources.
- ๐ Free Cloud Computing: Use Modal's $30 monthly credits (more than enough for most use cases)
- โก Serverless Infrastructure: No setup, no maintenance, automatic scaling
- ๐จ Full ComfyUI Support: Access to all custom nodes, workflows, and models
- ๐พ Persistent Storage: Keep your models and custom nodes across sessions
- ๐ง Easy Configuration: Simple INI-based config file for all settings
- ๐ฆ Auto-Setup: Automated setup script handles dependencies and volume creation
- โ Cloud-based ComfyUI deployment on Modal.com
- โ Persistent volume storage for models and custom nodes
- โ Automatic dependency management for custom nodes
- โ GPU support (A10G, T4, P100, V100, A100)
- โ Web-based UI accessible from anywhere
- โ Configuration-driven setup (no hardcoding required)
- โ Interactive shell access for container debugging
- โ Support for Hugging Face and CivitAI model downloads
- Linux, macOS, or Windows (with WSL2)
- Python 3.11+
- uv (link)
- Git
- Modal account (sign up free)
# Clone the repository
git clone https://github.com/Renks/MxC.git
cd MxC
# Create and activate virtual environment
uv venv
source .venv/bin/activate
# Install requirements
uv pip install -r requirements.txt
# Setup authentication (IMPORTANT!)
modal setup # Follow browser authentication
# Configure your setup
python setup_modal.py
# Deploy and run
modal serve main.pyYou will be given a public URL by the modal api, like so:
โฎ
๐จ Created web endpoint for ComfyUIContainer.ui =>
https://abc--appname-container-dev.modal.run
โฎ
Open the endpoint in a web browser to use ComfyUI! ๐
While the following URL will be used for monitor your app:
โฎ
โ Initialized.
View run at https://modal.com/apps/your-modal-username/main/app-id
โ Created objects.
โโโ ๐จ Created mount /path/to/main.py
โฎ
Step 1: Clone the Repository
git clone https://github.com/Renks/MxC.git
cd MxCStep 2: Create and Activate Virtual Environment
# Create virtual environment
uv venv
# Activate virtual environment
source .venv/bin/activate
# On Windows (PowerShell)
# .\.venv\Scripts\Activate.ps1
# On Windows (CMD)
# .venv\Scripts\activate.bat
Step 3: Install Dependencies
uv pip install -r requirements.txtOR Manually (If you fancy yourself)
pip install modal==1.3.0.post1 pyyaml==6.0.3 python-dotenv==1.2.1 configparser==7.2.0Step 4: Authenticate with Modal
Linux and MacOS
โPlease run this before you do anything else!
modal setupThis will open your browser to authenticate with Modal. Follow the prompts and return to the terminal.
Windows (WSL2)
๐ซท For users running Windows Subsystem for Linux 2 (WSL2), the setup process requires an initial authentication step on the Windows host.
-
Run Authentication on Windows:
Execute
modal setupin your main Windows command prompt or PowerShell environment. -
Locate the Configuration File:
Successful authentication generates a
.modal.tomlfile, typically saved in%USERPROFILE%\.modal.toml. -
Transfer to WSL2 Environment:
Copy this generated configuration file into your WSL2 home directory (~).
Example transfer command:
cp /mnt/c/Users/<your-windows-username>/.modal.toml ~/.modal.toml
Step 5: Configure Your Project
Edit โ๏ธ config.ini to customize your setup:
[RESOURCES]
gpu_type = t4 # Options: a10g, t4, p100, v100, a100
max_containers = 1
timeout = 3200
[FILESYSTEM]
volume_name = my-comfy-models
volume_mount_location = /root/per_comfy-storageStep 6: Run Setup Script
python setup_modal.pyThis script will:
โ
Create your persistent volume on Modal
โ Download essential models from Hugging Face (Skipped - very slow)
โ
Set up the folder structure
โ
Install custom nodes and dependencies
โ
Generate extra_model_paths.yaml
Step 7: Deploy and Run
modal serve main.pyYou'll see output like:
โ Initialized. View run at https://modal.com/apps/<your-modal-username>/main/<app-id>
โ Created objects.
โโโ ๐จ Created mount /path/to/main.py
โโโ ๐จ Created mount /path/to/extra_model_paths.yaml
โโโ ๐จ Created mount /path/to/config_comfyui.ini
โโโ ๐จ Created mount /path/to/comfy.settings.json
โโโ ๐จ Created mount /path/to/config.ini
โโโ ๐จ Created mount /path/to/.env
โโโ ๐จ Created mount PythonPackage:loaders
โโโ ๐จ Created mount /path/to/workflows
โโโ ๐จ Created function ComfyUIContainer.*.
โโโ ๐จ Created web endpoint for ComfyUIContainer.ui =>
https://<your-modal-username>--comfyui-app-comfyuicontainer-ui-dev.modal.run
๏ธ๏ธโก๏ธ Serving... hit Ctrl-C to stop!
โโโ Watching /path/to/workflows.
โโโ Watching /path/to/MxC.
--- Checking for custom node requirements ---
Installing requirements for: ComfyUI-GGUF
โฎOpen the endpoint in a web browser https://your-modal-username--comfyui-app-comfyuicontainer-ui-dev.modal.run to access ComfyUI!
Default volume name is my-comfy-models but you can change it in โ๏ธ config.ini file
[FILESYSTEM]
; Name of the volume to be created for persistent storage. Diffusion models and custom nodes will be stored here
volume_name = my-fancy-volume-name-goes-hereYour Modal persistent volume should be organized like this:
๐ id-provided-by-modal-dot-com/ # this name will be different
โโ ๐ checkpoints/ # manually download models here
โ โโ ๐ model.safetensors
โ โโ ๐ flux-dev.safetensors
โโ ๐ custom_nodes/ # add comfyui's custom_nodes here
โ โโ ๐ ComfyUI-GGUF
โ โโ ๐ rgthree-comfy
โ โโ ๐ seedvr2_videoupscaler
โ โโ ๐ comfyui-controlnet-aux
โโ ๐ diffusion_models/ # manually download models here
โ โโ ๐ z-image-turbo-Q8_0.gguf
โ โโ ๐ qwen-image-edit-2511-Q4_1.gguf
โ โโ ๐ seedvr2_ema_7b_fp16.safetensors
โ โโ ๐ seedvr2_ema_7b_sharp_fp16.safetensors
โโ ๐ loras/ # manually download loras here
โ โโ ๐ Qwen-Image-Edit-Lightning.safetensors
โ โโ ๐ flux-canny-controlnet-alpha.safetensors
โโ ๐ text_encoders/ # manually download clip models here
โ โโ ๐ qwen_2.5_vl_7b_fp8_scaled.safetensors
โโ ๐ unet/
โ โโ ๐ diffusion_pytorch_model.safetensors
โโ ๐ vae/ # manually download vae(s) here
โโ ๐ ema_vae_fp16.safetensors
โโ ๐ qwen_image_vae.safetensorsDownloading Models
The (It was very slow and tedious). You can also manually add models:setup_modal.py script handles this automatically
Make sure you drop into your modal volume's shell first modal shell --volume <your-volume-name>
Once in, cd to volume using cd /mnt/<your-volume-name>
-
From Hugging Face:
huggingface-cli download model-id --local-dir ./checkpoints
-
From CivitAI:
- Download models via the web interface
- Upload to your Modal volume using modal volume put
-
Using Modal CLI:
modal volume put <your-volume-name> path/to/local/model/checkpoints/model.safetensors
-
Using Wget CLI:
Instructions here.
The required directory structure is automatically generated upon the successful execution of python setup_modal.py. Make sure you ran setup_modal.py without any errors.
-
Access the Volume Shell
Open an interactive shell session within your Modal volume:
modal shell --volume <your-volume-name>
Note: Your volume will be mounted at
/mnt/<your-volume-name>. -
Navigate to the Target Directory
Change to the appropriate directory based on the model type:
# For diffusion models: cd /mnt/<your-volume-name>/diffusion_models/ # For checkpoints: cd /mnt/<your-volume-name>/checkpoints/
-
Download Models via CLI
Identify your desired model on Hugging Face. We will use unsloth/Z-Image-Turbo-GGUF as an example. Copy the direct download link for the file and use the
wgetutility to download it directly into the volume.Example
wget https://huggingface.co/unsloth/Z-Image-Turbo-GGUF/resolve/main/z-image-turbo-Q8_0.gguf
This command downloads
z-image-turbo-Q8_0.gguffile directly into your current working directory within the Modal volume.
Repeat for more models. You can also usewgetutility to downloadlorasand other files in their appropriate folders. -
Sync Changes (Important!)
Run
synccommand once you're done to save changes and thenexit.
Running ComfyUI
# Start the Modal app
modal serve main.py
# Access the UI
# Open URL provided in console in your browserInteractive Shell Access (Debugging)
To inspect the runtime environment or debug the filesystem, you can access the container using the following methods:
-
Active Instance Attachment (Recommended)
While โกmain.py is executing, run the following command in a separate terminal tab to attach an interactive shell to the running container:
modal shell main.py # in a new terminal tab ofcourseThis allows you to manage the filesystem in real-time and install additional packages as needed within the active Modal volume.
-
Legacy File Browsing (Deprecated)
Browse and debug the container filesystem:
# Linux/macOS ./browsefs.sh # Windows (PowerShell) .\browsefs.ps1
Managing Models and Custom Nodes
# List files in your volume
modal volume ls <your-volume-name>
# Upload a model
modal volume put <your-volume-name> path/to/model.safetensors checkpoints/
# Download from volume
modal volume get <your-volume-name> checkpoints/model.safetensors ./local_path/Monitoring Your App
# View logs
modal logs --app comfyui-app
# List running apps
modal app listEdit โ๏ธ config.ini to customize your deployment:
[TOKENS]
HF_TOKEN = .env # Store in .env file for security
CIVITAI_API_TOKEN = .env
[WEB]
port = 8000
host = 0.0.0.0
[FILESYSTEM]
volume_name = my-comfy-models
volume_mount_location = /root/per_comfy-storage
comfyui_dir = /root/comfy/ComfyUI
[RESOURCES]
gpu_type = a10g # CPU if commented out
max_containers = 1
timeout = 3200
max_inputs = 10
cpu = 1
memory = 16384
[MODEL_PATHS]
checkpoints =
models/checkpoints/
/root/per_comfy-storage/checkpoints/
loras =
models/loras/
/root/per_comfy-storage/loras๐ง Documentation in Progress
More instructions will be added later. Please refer to the inline comments within โ๏ธ config.ini for detailed parameter descriptions and setup instructions.
- API Keys: Store tokens in a .env file (never commit to git)
- Volume Access: Only accessible within Modal containers
- Authentication: Modal handles all infrastructure security
- Data Privacy: Models stay in your isolated container
Create a .env file:
Token values are optional but make sure keys exist. You can rename .env.BAK to .env for ease.
HF_TOKEN=your_huggingface_token
CIVITAI_API_TOKEN=your_civitai_token| Resource | Cost | Modal Credits |
|---|---|---|
| A10G GPU (1 hour) | ~$1.50 | 0.05 credits |
| T4 GPU (1 hour) | ~$0.35 | 0.01 credits |
| Storage | Free | Free |
| Monthly Budget | ~$45 | $30 |
You get $30 credits per month = free unlimited usage!
Virtual Environment Not Activating
# Recreate the venv
rm -rf .venv
uv venv # OR 'python3.11 -m venv .venv'
source .venv/bin/activate
uv pip install -r requirements.txtModal Authentication Failed
rm ~/.modal.toml # Windows (CMD): del "%USERPROFILE%\.modal.toml"
modal setup # Re-authenticateVolume Not Found
# List all volumes
modal volume list
# Create volume if missing
modal volume create my-comfy-modelsCheck the running container(s)
# List all running containers with their ID
modal container list
# Attach shell to a specific container
modal shell <Container ID>
Models Not Loading
Check the volume structure:
modal volume ls my-comfy-models diffusion_models/
# OR
modal volume ls my-comfy-models checkpoints/๐ MxC/
โโ๐ workflows/ # ComfyUI workflow templates (will be uploaded)
โ โโ๐ README.md # README for workflows (auto-generated)
โ โโ๐ example_workflow.json # Dummy workflow (doesn't exist)
โโ๐ README.md # This file
โโ๐ setup_modal.py # Setup and initialization script
โโ๐ main.py # Main Modal app
โโ๐ loaders.py # Python library to load and parse config.ini file
โโ๐ generate_model_paths.py # YAML config generator
โโ๐ config.ini # Configuration file for the project (Important)
โโ๐ requirements.txt # Python dependencies
โโ๐ extra_model_paths.yaml # ComfyUI's extra paths (will be uploaded to container)
โโ๐ comfy.settings.json # Settings for ComfyUI (will be uploaded to container)
โโ๐ config_comfyui.ini # Settings for ComfyUI's Manager (will also be uploaded)
โโ๐ .env.BAK # Environment variables template
โโ๐ .env # Environment variables (Store your tokens here)
โโ๐ .emptyfile # Used for creating directories inside Modal volume
โโ๐ pyproject.toml # Project file (ignore)
โโ๐ uv.lock # Project file (ignore)We welcome contributions! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Modal.com - For incredible free cloud compute credits
- ComfyUI - For the amazing node-based UI
- Hugging Face - For model hosting and APIs
- ๐ Modal Documentation
- ๐ ComfyUI Issues
- ๐ฌ Modal Community
Made with โค๏ธ for the AI community