# Netlify setup for AI agents
This is Netlify's documentation for AI coding agents. Use it when your user has asked you to set up Netlify or to deploy a site with it. It lists the commands to run, in order.
One step always needs the user: approving the Netlify login in their browser, in step 2. A user with more than one Netlify team is also asked which team, in step 4. Nothing is created or published on Netlify before they approve. Steps 1 and 2 only install the CLI and request that login.
---
## If your sandbox blocks a command
Some agents, Codex among them, run commands in a sandbox with no network and no access to files outside the project. The Netlify CLI needs both. It keeps the login in the user's home folder and it talks to Netlify's API.
The signs are "EPERM" or "operation not permitted" from any `netlify` command, and "Could not resolve host" from `npm` or `curl`.
When you see one, don't retry the command and don't skip the step. Do the first of these that you can:
1. Request approval to run the command outside the sandbox.
2. If your session can't ask for that, first finish the work that needs no Netlify command, such as writing the site into `public/`. Then give the user both ways forward in one message:
- You finish it: "Netlify needs network access and its login file, which my sandbox blocks. Allow full access for this session (in Codex, type `/permissions`), then tell me to continue."
- They finish it, in their own terminal, from the project folder: `netlify init`, then `netlify deploy --prod --dir public`. `netlify init` there logs them in, installs the skills and MCP server, and creates the project.
After the user allows access, start again from step 1.
---
## 1. Install the CLI: `npm install -g netlify-cli@latest`
Run `netlify --version` first. Install only if it is missing or older than 27.20.0.
npm prints warnings about install scripts. They are expected. If `netlify --version` works afterwards, continue.
---
## 2. Log in: `netlify login --request "<your agent name> wants to set up Netlify"`
Run `netlify status` first. If it shows a logged-in user, go to step 3.
Use `--request`, not plain `netlify login`. Plain login waits on a browser window and times out when run by an agent.
`--request` prints a login URL and a `netlify login --check <ticket>` command.
1. Give the user the URL: "Approve this Netlify login and I'll set up the project and publish your site: <URL>"
2. Run the check command every 10 seconds, for up to 10 minutes. It prints "Status: pending" until the user approves, then "Status: authorized". "Status: denied" means the user declined or the link expired: stop and tell them.
3. If you can't wait that long, stop here. When the user says they approved, run the check command once and go to step 3.
---
## 3. Set up the agent tools: `netlify init`
Run it in the user's project folder. A new, empty folder works. Leave out `--skip-agent-setup` and `--skip-mcp-setup`.
`netlify init` installs the Netlify skills for your agent and adds the Netlify MCP server. Without a terminal it then prints the commands for step 4 and exits. Run it even when the user only asked for a deploy, since it is what sets the project up for later work.
Check its output:
- "Installed Netlify skills" and "Added the Netlify MCP server" mean it worked. On a later run, "Synced" or "up to date" for the skills, and a note that the MCP server is already there, mean the same.
- "Could not sync" or "Could not write", with "operation not permitted" or "EPERM", means your sandbox blocked the files and nothing was installed. Follow "If your sandbox blocks a command" above. If the user declines, continue and mention it in step 6.
- A printed command that adds the MCP server, such as `claude mcp add …` or `npx add-mcp …`, means init could not add it itself. Run that command. For `npx add-mcp`, add `-y -a <your agent name>`. If it prints `netlify init --mcp-scope user` instead, leave it for the user, since that changes their settings for every project.
- An interactive menu means you have a terminal. If the menu asks which AI agents should get the MCP server, select your own agent and confirm. Cancel any other menu without answering it. The agent tools are installed by then, so there is no need to run init again.
If the user's task doesn't involve a deploy, go to step 6.
---
## 4. Link or create the project: `netlify sites:create --name <name> --account-slug <team>`
Use the first case that applies.
1. The folder is already linked: `netlify status --json` shows `"linked": true`. Its exit code doesn't matter. Go to step 5.
2. The folder has a git remote: run `netlify link --git-remote-url <origin url>`. If it links, go to step 5.
3. Otherwise create a project with `netlify sites:create --name <name> --account-slug <team>`. Pass both flags.
- Team: run `netlify teams:list --json`. If the user already named a team, use it. If there is one team, use it and tell them in step 6. If there are several, ask one question that lists the team names and offers the one with `"default": true` as the suggestion: "Which Netlify team should this project go in? I'd suggest <default team>." Then continue with their answer.
- Name: the folder name, with anything other than letters, numbers, and hyphens replaced by a hyphen, under 64 characters.
- If the name is taken, the command adds a random suffix itself. Take the final name and URL from its "Project Created" output. If it asks for a project name instead, you have a terminal: cancel it and run it again with a short suffix.
---
## 5. Deploy: `netlify deploy --prod --dir <site folder>`
If there is nothing to deploy yet, go to step 6.
Deploy only once the folder is linked, which step 4 does. In a folder that isn't linked, `netlify deploy` creates another project.
Deploy the site's own folder, not the whole project folder. After step 3 the project folder can hold agent config files, and a deploy of the whole folder publishes them.
- Plain files, such as an `index.html`: keep them in their own folder, for example `public/`, and pass `--dir public`.
- A project with a build step: leave out `--dir`. `netlify deploy` runs the build and deploys the framework's output folder on its own. Pass `--dir <build output folder>` only when the project uses a custom build script and `netlify.toml` sets no `publish`. In that one case, leaving it out publishes the whole project folder.
For a project you created in step 4, use `--prod`. Nothing was live before, so this puts the site on its main URL.
For a project that already existed, leave out `--prod`. That publishes a draft and leaves the live site alone. Use `--prod` only if the user asked for a production deploy.
---
## 6. Tell the user
- The site URL, or the "Draft URL" for a draft.
- The Netlify team the project is in.
- Whether the Netlify skills and MCP server were installed. The MCP server loads the next time the agent starts in this folder. If a sandbox blocked them, say that running `netlify init` in their own terminal installs them.
- How to get a deploy on every push: they run `netlify init` in their own terminal. It connects the Git repository and asks them to authorize GitHub, so it is theirs to run.
---
## Help
`netlify --help` lists everything the CLI can do. Netlify's docs for agents are at https://docs.netlify.com/llms.txt.
Deploy to the web with a single command from Netlify. Give your AI agent the ability to create sites, deploy apps, and manage serverless infrastructure — no human in the loop.
The preferred web platform for millions of agent-built sites.
Start shipping
Copy this instruction and give it to your agent
fetch https://netlify.ai to start deploying
FAQ
Is it free?
Yes. Netlify has a generous free tier that includes hosting, serverless functions, edge functions, and more.
Do I need a Netlify account?
Agents can build and deploy static sites without needing a Netlify account. For more complex setups, sign up for a free Netlify account.
Can I use my own domain?
Yes. You can connect custom domains to any Netlify site, with automatic HTTPS included. You can also buy domains directly through your Netlify account.
What agents/tools does this work with?
All of them. Claude Code, Cursor, Codex, Gemini CLI, or any AI agent that can run commands.
What can my agent deploy to Netlify?
Anything that runs on the web: websites, web apps, APIs, dashboards, games, blogs, storefronts, documentation, prototypes, portfolios, and more.
What does my agent get access to?
The full Netlify platform - instant deploys, serverless functions, edge functions, environment variables, forms, identity, and more.
Can my agent manage existing sites?
Yes. Your agent can deploy updates, manage environment variables, configure settings, and access the Netlify API for any site on your account.