Apps Script: Exceeded maximum execution time
Last verified
Exceeded maximum execution timeWhat it means
Apps Script stops any execution that runs past its time limit and logs this message. Google's quotas page lists a script runtime of 6 minutes per execution for both consumer and Google Workspace accounts. Custom functions (formulas you write in Apps Script and call from a cell) are limited to 30 seconds, and simple triggers such as onEdit and onOpen cannot run longer than 30 seconds either.
The limit is per execution, not per day, so nothing is wrong with your quota. The script simply did too much work in one run. Whatever it finished before the cut-off stays done; whatever came after did not happen, which can leave a sheet half-updated.
The usual culprits are loops that call getValue or setValue one cell at a time, and long sequences of UrlFetchApp.fetch calls, each of which waits on a remote server.
What it looks like
// slow: one service call per cell
for (let r = 2; r <= last; r++) {
const v = sheet.getRange(r, 1).getValue();
sheet.getRange(r, 2).setValue(transform(v));
}
// fast: one read, one write
const vals = sheet.getRange(2, 1, last - 1, 1).getValues();
sheet.getRange(2, 2, vals.length, 1).setValues(vals.map(([v]) => [transform(v)]));Why it happens
- Reading or writing cells one at a time inside a loop instead of using getValues and setValues on a whole range.
- Calling an external API sequentially for many rows, with each request waiting on a slow server.
- Processing a dataset that has grown past what fits in 6 minutes.
- A custom function doing network calls or heavy work that exceeds its 30-second limit.
- Utilities.sleep calls or retry loops that add up across a long run.
How to fix it
- Open Executions in the Apps Script editor and check the duration and the last log line before the stop.
- Batch spreadsheet I/O: read the full range with getValues once, work on the array in memory, and write back with a single setValues.
- Use UrlFetchApp.fetchAll to send independent HTTP requests in parallel instead of one at a time.
- Split the job into chunks: save progress (for example the last processed row) in PropertiesService, stop well before 6 minutes, and let a time-driven trigger continue from there.
- For custom functions, move slow work into a scheduled script that writes values into the sheet, and have the formula read those cells.
- Re-run and confirm the duration in Executions is comfortably under the limit.
How to stop it recurring
Design long jobs as resumable batches from the start: track a cursor in script properties, check elapsed time inside the loop, and exit cleanly at around 4 to 5 minutes. Keep spreadsheet reads and writes in bulk. Remember that time-driven trigger runs also count against a daily total trigger runtime (90 minutes a day on consumer accounts, 6 hours on Workspace), so faster code protects that budget too.
Official documentation: developers.google.com/apps-script/guides/services/quotas. See all Apps Script error messages or the Apps Script limits and quotas.
Related errors
- Service using too much computer time for one dayService using too much computer time for one day.
- Service Spreadsheets timed out while accessing documentException: Service Spreadsheets timed out while accessing document with id…
- Too many simultaneous invocations: SpreadsheetsException: Too many simultaneous invocations: Spreadsheets
Definitions
- Google Apps ScriptGoogle Apps Script is Google's cloud-hosted JavaScript platform for automating Google Workspace: Sheets, Gmail
- Error HandlingError handling is the practice of anticipating, detecting, and responding to errors in software execution, inc
- Rate LimitingRate limiting is a technique that controls the number of requests a client can make to a server within a given
- OAuth 2.0OAuth 2.0 is the IETF authorization standard (RFC 6749) that lets an app access your account in another servic
Quick answers
What does "Exceeded maximum execution time" mean in Apps Script?
Apps Script stops any execution that runs past its time limit and logs this message. Google's quotas page lists a script runtime of 6 minutes per execution for both consumer and Google Workspace accounts. Custom functions (formulas you write in Apps Script and call from a cell) are limited to 30 seconds, and simple triggers such as onEdit and onOpen cannot run longer than 30 seconds either.
How do I fix "Exceeded maximum execution time"?
1. Open Executions in the Apps Script editor and check the duration and the last log line before the stop. 2. Batch spreadsheet I/O: read the full range with getValues once, work on the array in memory, and write back with a single setValues. 3. Use UrlFetchApp.fetchAll to send independent HTTP requests in parallel instead of one at a time. 4. Split the job into chunks: save progress (for example the last processed row) in PropertiesService, stop well before 6 minutes, and let a time-driven trigger continue from there. 5. For custom functions, move slow work into a scheduled script that…
Run the job somewhere with its own limits
If a script keeps hitting its host's quotas, an Autonoly workflow can run the same steps on a schedule in an isolated cloud container, and the AI agent has a terminal with Python for steps that need code. Autonoly has limits of its own, priced in credits.
Also see Agent terminal & SSH.