Square CloudSquare Cloud

How to use an AI agent to fix deploy errors

An AI agent fixes deploy errors well when it gets the full log, the start command, the dependency files and what changed. Ask for the cause before the fix, handle one error at a time and review every change before applying it.

Updated 8 min read

Learning objectives

After reading this article you will be able to:

  • Gather the context an AI agent needs to diagnose a failed deploy
  • Ask for a diagnosis and review the fix before applying it
  • Recognize the errors where AI helps and where it falls short
On this page

A failed deploy usually leaves two things behind: a long log and a developer in a hurry. Pasting that log into an AI assistant has become the first move for a lot of people, and it works well much of the time. But the quality of the answer depends almost entirely on what you give the model and how you ask.

This guide shows how to use an AI agent (in a chat, in your editor or in your hosting dashboard) to diagnose and fix a broken deploy without trading one error for another. The method works with any tool: give the right context, ask for the cause before the fix and review what comes back. If you can't yet find the line that matters in a log, start with how to read build errors.

What does the agent need to see?#

The agent has no access to your server unless you grant it. It works with what is in the conversation, and the most common reason for a wrong diagnosis is missing context. Before you ask, collect:

  1. The full log, from the start of the install to the end. The last lines describe the consequence; the cause is often well above them. A cut log makes the agent guess.
  2. The start command your host runs (node index.js, npm start, gunicorn app:app). Many errors come from a wrong main file or a script that doesn't exist.
  3. The dependency files: package.json and the lockfile, requirements.txt or the equivalent. Without them, the agent can't know what got installed.
  4. The runtime and version the app runs on in production, which may not match your machine.
  5. The names of the environment variables set on the server, never the values.
  6. What changed since the last deploy that worked: a commit, a new dependency, a renamed variable.

A short script gathers most of this into one file without copying secrets:

bash
{
  echo "## Local runtime"; node -v 2>/dev/null; python3 --version 2>/dev/null
  echo "## Dependencies"; cat package.json requirements.txt 2>/dev/null
  echo "## Expected variables (names only)"; sed 's/=.*//' .env 2>/dev/null
  echo "## Recent commits"; git log --oneline -5
  echo "## Files changed in the last commit"; git diff --stat HEAD~1
} > context.txt

The log comes from your host: copy it from the dashboard, the CLI or the server's terminal. If you have never read a stack trace slowly, how to read your application logs walks you through it.

How should you ask for the diagnosis?#

The shape of the request changes the answer. Two habits make the biggest difference.

One error at a time. If the log has three failures, the first one usually causes the others. Asking to "fix everything" produces a large change that is hard to review and touches code that wasn't broken.

The cause before the fix. Asking for the fix right away makes the model pick a hypothesis and write code for it, even when the evidence points elsewhere. Splitting the steps forces the agent to show its reasoning, and you check it against the log.

A request template that works well:

text
My deploy failed. Don't propose a fix yet.

1. Quote the first log line that points to the cause.
2. List up to three likely causes, most likely first,
   and say which evidence in the log supports each one.
3. Tell me what information is missing to be sure.

Runtime: Node.js (LTS). Start command: node index.js.
What changed: I replaced Express with Fastify and added DATABASE_URL.

[full log]
[package.json]

Once the cause is clear, ask for the smallest change that fixes it: "Propose the smallest fix for cause 1. Show the diff and explain why it resolves the line you quoted." If the agent asks for a file you didn't send, send it. That's a good sign: it noticed missing context instead of making something up.

How do you review the proposed fix?#

An agent's fix is a suggestion, not a fact. Before applying it, run through these questions:

  • Does it explain the quoted line? For a missing module, the expected change is one line in the dependency file or an import path. If the diff touches five files, be suspicious.
  • Does the package exist? Check npm or PyPI for who publishes it, whether the name matches the official documentation exactly and whether the suggested version exists.
  • Is it a workaround? --force, --legacy-peer-deps, a try that swallows the exception or turning off certificate checks (NODE_TLS_REJECT_UNAUTHORIZED=0) make the error disappear from the log without fixing the cause.
  • Does it put a secret in code? If the suggestion writes a token or password into a file, reject it and read the value from an environment variable.
  • Can you reproduce it? Run it locally the way the server does: node_modules deleted and npm ci, or a clean virtual environment with pip install -r requirements.txt. The gap between the two environments is covered in works locally but not in production.

Apply the fix in its own commit so a git revert undoes it if things get worse. Then deploy again and read the log again. If the error changed, that's progress: start over with the new log rather than asking the agent to "continue" from the old diagnosis.

Which errors does AI help with most?#

AI does best on errors with a clear message and a known cause, the kind that show up in thousands of projects. These four are typical cases:

Error Typical log line What to show the agent Common fix
Missing module Error: Cannot find module 'express' or ModuleNotFoundError: No module named 'requests' Dependencies, lockfile and folder structure Declare the package in dependencies or fix the import path
Port The app starts but doesn't respond; or Error: listen EADDRINUSE: address already in use :::3000 The code that calls listen and the host's port variables Listen on 0.0.0.0, on the port the host sets
Missing variable KeyError: 'DATABASE_URL' in Python; in Node.js, an undefined that breaks later Where the code reads the variable and the names set on the server Set the variable in the environment and restart
Out of memory JavaScript heap out of memory, MemoryError or exit code 137 RAM usage, the container limit and what the code loads Reduce usage or raise the limit

Three of them have their own article: Cannot find module, EADDRINUSE and port binding and out-of-memory (OOM) errors.

With memory, ask for extra care. Raising the limit treats the symptom; if usage keeps growing, there's a leak, and the agent only finds it if you show the code that accumulates data and the usage curve over time.

Where does AI get it wrong?#

Knowing the limits saves hours:

  • It can't see what you didn't show. If the real error is in an external service (a database refusing connections, an expired credential, a firewall), the app log only shows the effect. The agent will propose code changes for a problem that isn't in the code.
  • It can make things up. OWASP lists suggesting insecure or non-existent libraries among the risks of LLMs. The same goes for CLI flags, configuration options and platform variables. An invented name may match a third-party package nobody has audited.
  • Confidence isn't evidence. The model answers in the same tone whether it's right or wrong. That's why the request demands the log line behind each hypothesis. More on this in LLM hallucinations.
  • It fixes the symptom. Without the project's context, the shortest way to make the error vanish tends to win: hardcoding a port, downgrading a version, turning off a check.
  • An agent with permissions acts. If it can edit files and restart the app, have it propose and wait for your approval on actions that change something. Logs can contain text from users, and that text can carry instructions; the risk is explained in prompt injection.

When the agent gives two different answers for the same log, or insists on a cause the log doesn't show, stop and read it yourself. It helps you go faster; it doesn't replace reading.

How to do this on Square Cloud#

On Square Cloud, the AI agent is called Cubic and lives in the dashboard, included in every plan, with a daily and weekly token budget. It reads your application's logs to diagnose the failure, writes code and runs safe actions on your applications, at your request. That covers the first step of this guide: instead of copying the log, you ask for the diagnosis in the conversation and Cubic reads the output directly, including the dependency install output, which shows up in the logs.

The method stays the same: ask for the cause before the fix, one error at a time. Every file Cubic edits or deletes can be undone from the chat for as long as the conversation lasts, which leaves room to try a fix and roll it back. Some errors in the table have a direct answer on the platform: a web application listens on 0.0.0.0 on the port in the PORT variable; a new environment variable takes effect on the next restart, with no rebuild; and an application that runs out of memory stops and doesn't come back on its own, so you raise its RAM and start it again.

For a broader review, the /checkup command in the chat runs a read-only check: dependencies with known vulnerabilities, credentials written in the code (file and line, never the value), the RAM peak of the last 24 hours against the limit, and automatic restart turned off. If you prefer your editor's agent, the MCP server connects Claude Code, Cursor or VS Code to your account, with access to status, logs, metrics and files.

See what Cubic does and each plan's limits on the Cubic page.

AI

Host AI apps in always-on containers

AI agent

FAQs

Can I paste my .env file into the chat so the AI finds the error?

No. Send only the variable names and say which ones are set on the server. The values are secrets and don't help the diagnosis: what matters is whether the variable exists in the environment.

Can AI fix the deploy on its own?

It usually gets common errors right, such as a missing dependency or the wrong port, but it only sees what you showed it. Review every change and confirm the fix with a new deploy and a read of the logs.

Why did the AI suggest a package that doesn't exist?

Language models can invent package names, options and configuration variables. Check the official registry (npm, PyPI) and the documentation before installing anything you don't know.

What's the difference between an AI chat and an agent for fixing a deploy?

In a chat, you copy the log and apply the fix by hand. An agent with access to the right tools reads the logs and files and proposes the change directly, but it is still limited to what it can see and depends on your review.

Next articleHow to connect Claude, Cursor or VS Code to your server over MCPTo connect an AI client to a remote MCP server, add its URL, authorize with OAuth or an API key and check the exposed tools. Steps for Claude, Cursor and VS Code.