The guarded script evaluator checks scripts that client code sends to the server, and it accepts only a small JavaScript subset. Scripts outside that subset are rejected, logged, or routed to the sandbox, depending on the sender and the enforcement phase. Fix them by moving logic into a sandbox-enabled script include, or by creating an exemption.
How the evaluators decide what runs
Client code reaches the server in two ways. A filter or query parameter in a URL can carry a script, such as a javascript: filter that a logged-out visitor opens from a link. The AJAXEvaluate system API lets client code run a script on the server and read the result. Both routes produce untrusted scripts.
When a script arrives, a server-side evaluator decides whether it is trusted. Trusted scripts run in the JavaScript engine. Untrusted scripts run in a restricted sandbox environment through one of two evaluators:
| Evaluator | What it accepts | When a script reaches it |
|---|---|---|
| Guarded script evaluator | A narrow language: one simple expression or function call, plus a restricted API list | The default route for untrusted scripts |
| Script sandbox evaluator | JavaScript engine and sandbox features, minus a list of restricted methods | The script has a guarded-script exemption, or an authenticated user sent it during Phase 1 |
Script includes and client-side scripts sit outside both evaluators, so the checks apply to the script text that arrives from a browser or a link.
What the guarded script language allows
The guarded evaluator does not run ordinary JavaScript. It accepts a single simple expression or function call built from these forms:
| Feature | Supported form |
|---|---|
| Literals | Numbers, strings, booleans, null, undefined |
| Operators | Addition, subtraction, less-than, strict inequality, logical and, instanceof, typeof, and the ternary operator |
| Arrays and properties | Array literals, dot-notation property access, indexed access with a constant number |
| Calls | Calls to script includes that have Sandbox enabled selected |
Variable and function declarations, assignment with the equals sign, control flow such as if, and multiple statements are rejected. A typical case is a filter script that declares a variable, branches on a field value, and builds a query string. The whole script is rejected. The fix is structural: move the branching into a script include and call it from the original script with one expression.
Calls are limited to a restricted list of APIs. The gs object allows date-range helpers such as beginningOfToday and daysAgoStart, and GlideRecord allows read methods such as getValue. Built-in JSON.stringify is on the list, as covered in JSON stringify in server-side scripts. A method absent from the list is unsupported here, whatever it does elsewhere.
Enforcement phases for authenticated traffic
For the wider access and security model around these settings, see the instance security and access control section.
Guest traffic is enforced from the start on each instance. A script sent by an unauthenticated visitor, such as one from a public page, is rejected, listed and logged.
Authenticated traffic depends on the instance type:
| Instance type | Default behavior for authenticated scripts |
|---|---|
| New instance | Enforced at Phase 3 from the start |
| Upgraded cloud-based instance | Starts at Phase 1 and advances automatically to Phases 2 and 3, about two weeks per phase |
| Upgraded on-premise instance | Not enforced. Scripts are detected and recorded, and an administrator sets when to move on |
The three phases on a phased instance:
| Phase | What the evaluator does | At the end of the phase |
|---|---|---|
| 1. Detection | Lets scripts run. Records incompatible syntax, not incompatible APIs | Creates automatic exemptions for incompatible-syntax scripts |
| 2. Syntax enforcement | Rejects incompatible syntax and logs errors. Records incompatible APIs without rejecting them | Creates automatic exemptions for scripts that call incompatible APIs |
| 3. Full enforcement | Rejects incompatible scripts of both kinds and logs errors | Further exemptions must be created by hand |
Automatic exemptions are a holding measure, not a fix. Once a script is rewritten, remove its exemption.
Detection depends on traffic. A quarterly or annual job may not have run before the instance moved into Phase 3, so test such scripts from the Scripts – Background module, with Execute in sandbox selected, before that move.
The phase property, com.glide.script.sandbox.ks.watchdog.phase, should be changed through the GlideGuardedScript methods rather than by hand. Setting it by hand skips the automatic exemptions that those methods create on each transition. The enabled property, com.glide.script.sandbox.ks.watchdog.enabled, defaults to true and should stay on in production, because setting it to false removes the guarded protection.
What the script sandbox evaluator blocks
The script sandbox evaluator is the less strict route. A script that calls a restricted method fails to execute in the sandbox. The main restricted groups are:
| Object | Restricted methods (examples) |
|---|---|
| GlideRecord and ScopedGlideRecord | insert, update, deleteRecord, deleteMultiple, updateMultiple |
| GlideSystem (gs) | getProperty, setProperty, addInfoMessage, setRedirect, setReturn, eventQueue, log, logError, logWarning |
| GlideDateTime, GlideDate, GlideTime | Many calculation and setter methods, including add, subtract, compareTo and setValue |
The gs log methods stay blocked unless glide.security.sandbox_no_logging is set to false, a trade-off to make deliberately.
Writes are the other restriction. Inserts, updates and deletes are blocked inside the sandbox, and calls such as current.update() are ignored.
Reviewing rejected scripts in the Incompatible Guarded Scripts list
The list is at All > System Diagnostics > Guarded Script > Incompatible Guarded Scripts, and it requires the guarded_script_admin or admin role. The columns that matter most are:
| Column | What it tells you |
|---|---|
| Is Authenticated | Whether an authenticated user or a guest sent the script |
| Occurrence count | How often the script has been seen |
| Normalized script | Scripts with the same logic and authentication type share one row |
| Page Title | The endpoint that sent it, or the script name for a scheduled job |
| Stack trace | The JavaScript stack trace captured the first time the script was recorded |
Normalization means one row can cover several variants, so one fix covers them both. Rejected scripts also appear in System Logs > System Log > Errors, with a message beginning “KittyScript validation failed for”. Match its script name and source to the list entry before you change anything.
Moving complex logic into a script include
For logic that can be rewritten, a script include is the usual answer, because it runs outside the sandbox and can use the full set of features the JavaScript engine supports.
- Use the stack trace, or a fragment of the normalized script, to find the original.
- Remove the complex logic from that script.
- Create a script include that holds the removed logic, with a clearly named method.
- On the Script Include form, select Sandbox enabled, but only where the sandbox needs to call it.
- Replace the original script with one simple call to the include.
- Test from the Scripts – Background module with Execute in sandbox selected.
A script include marked Glide AJAX enabled needs an access control unless its privacy is set to public, and Sandbox enabled is a separate option. The GlideAjax calls from the client guide covers the client side of that pattern.
Creating an exemption, and what it costs
For a business-critical script that cannot be rewritten, select the row and choose Add Exemption. The exemption covers each runtime variation that normalizes to the same form with the same authentication type, and it sends the script to the sandbox evaluator. Use exemptions sparingly. Exemptions are not tracked in update sets, so export and import them by hand when you promote a change.
Common rejection causes and fixes
| What you see | Likely cause | Fix |
|---|---|---|
| A guest-facing filter throws an error | The script declares a variable or uses an if block | Move the branching into a sandbox-enabled script include |
| A query condition calls a helper that fails | The helper is a script include without Sandbox enabled | Select Sandbox enabled on that include, if the sandboxed script needs it |
| A sandboxed script logs nothing | gs.log, gs.logError and gs.logWarning are restricted | Enable the logging property deliberately, after weighing the trade-off |
Frequently asked questions
Why did a script that worked last month start failing?
On an upgraded cloud-based instance, enforcement advances automatically, about two weeks per phase. Scripts recorded in Phases 1 and 2 receive automatic exemptions and run in the sandbox evaluator until someone removes those exemptions, so a call to a restricted method such as gs.setProperty still fails there. A script first sent during Phase 3 is rejected and logged. Check the Exemption column to see which case applies. Rewrite it or create an exemption.
Can the guarded script evaluator be switched off?
The enabled property can turn it off, but that sends untrusted scripts to the sandbox and drops the guarded checks, so keep it on in production.
What does the guarded script language accept?
It accepts a single simple expression or function call. The allowed forms are literals, a fixed set of operators, array literals, dot-notation property access, indexed access with a constant number, and calls to script includes that have Sandbox enabled selected. Variable and function declarations, assignment, if blocks and multiple statements are rejected.
How does the guarded script evaluator differ from the script sandbox evaluator?
The guarded script evaluator is the default route for untrusted scripts and accepts only the narrow language. The script sandbox evaluator is the less strict route. It accepts JavaScript engine and sandbox features minus a list of restricted methods, and it receives a script that has a guarded-script exemption or one an authenticated user sent during Phase 1.
For the wider scripting topics, see the ServiceNow platform guides or the ServiceNow solutions, guides and services page.