Container-bound Scripts

A script is bound to a Google Sheets, Docs, Slides, or Forms file if it wascreated from that document rather than as astandalone script.The file that a bound script is attached to is called a "container."Bound scripts generally behave like standalone scripts except that theydo not appear in Google Drive, they cannot be detached from the filethey are bound to, and they gain a few special privileges over the parent file.

Note that scripts can also be bound to Google Sites, but these scripts arealmost always deployed asweb apps. Scriptsbound to Google Sheets, Docs, Slides, or Forms can also become web apps, althoughthis is uncommon.

Note: Bound scripts are effectively unpublishedadd-ons that function only forthe file they are bound to.

Create a bound script

Google Docs, Sheets, or Slides

To create a bound script in Google Docs, Sheets, or Slides, open a document inDocs, a spreadsheet in Sheets, or a presentation in Slides and clickExtensions>Apps Script. To reopen the script inthe future, do the same thing or open the script from theApps Script dashboard.

Google Forms

To create a bound script in Google Forms, open a formand click More>Scripteditor. To reopen the script in thefuture, do the same thing or open the script from theApps Script dashboard.

Note: Theclasp tool can't create bound scripts,but it can clone and edit them.

Special methods

Bound scripts can call a few methods that standalone scripts cannot:

For more information, see theguide to extending Google Sheets ortheguide to extending Google Docs.

Note: These methods are only available to bound scripts run fromthe script editor, menu items, dialogs, sidebars, or triggers. When a boundscript is run as a web app or via theApps Script API, these methods are notavailable.

Custom menus, dialogs, and sidebars

Bound scripts can customize Google Sheets, Docs, and Forms by addingcustom menus anddialog boxes or sidebars. Keep in mind,however, that a script can only interact with the user interface for thecurrent instance of an open file. That is, a script bound to one documentcannot affect the user interface of another document.

Add-ons can also add custom menus, dialogs and sidebars.It is recommended to develop add-ons usingstandalone scripts.

Triggers

Bound scripts can usesimple triggerslike the specialonOpen() function, which runs automatically whenever a fileis opened by a user who has edit access. Like all types of scripts, they canalso useinstallable triggers.

Custom functions

Acustom function is a function in ascript bound to Google Sheets that you call directly from a cell using thesyntax=myFunctionName(). Custom functions are thus similar to the hundreds ofbuilt-in functions in SheetslikeAVERAGE orSUM except that you definethe custom function's behavior.

Access to bound scripts

Only users who have permission to edit a container can run its bound script.Collaborators who have only view access can't open the scripteditor, although if they make a copy of the container file, they become theowner of the copy and can see and run a copy of the script.

To learn how to share a script's container file, refer toShare files fromGoogle Drive.

All container-bound scripts use the same owner, viewer, andeditor access list defined for the container file. The container owner takesownership of a new script project regardless of who created it.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-06-04 UTC.