Basic Usage
Configuration Options
Option Reference
What AgentScript Blocks
Syntax Allowlist
The table above lists names. The preset also has an allowlist of syntax (AllowedSyntaxRule, AGENTSCRIPT_ALLOWED_NODE_TYPES): a script may only contain the node types on it, so a construct no rule names is refused as well. Not on the list are this, classes, new.target, import.meta, debugger, with, yield, dynamic import() and module declarations.
Four constructs share their node type with an allowed one and are constructs of their own. They are refused, and allowed only when listed under their own name:
Listing
ForOfStatement allows for…of, not for await…of.
async function __ag_main() { ... } without parameters. Every other function declaration is refused, also one that carries that name.
Object Is Used Directly
The preset refuses the reflection functions by property name, wherever they are read and on whatever object: getPrototypeOf, setPrototypeOf, defineProperty, defineProperties, getOwnPropertyDescriptor, getOwnPropertyDescriptors, getOwnPropertySymbols and the legacy accessor methods (__defineGetter__, __lookupGetter__, …). Object.create is refused on Object. So that this holds, the global Object may only be used directly (the requireDirectObjectUse option of NoGlobalAccessRule, which the preset switches on):
Object is not the global and is left alone.
Regular-Expression Methods
AgentScript has no regular expressions: regex literals are refused, and so arematch, matchAll and search on a value of the script, with any argument, because a string passed to them is compiled into a regular expression. The check sees the call in every static spelling of the method name (x.match, x['match'], a template literal without substitutions), through call / apply / bind, as a template tag and without an argument.
A method of that name on a global the host declared as an object (hostObjectGlobals: a tool namespace such as docs.search(args)) is the host’s own method and is accepted.
With requireDirectRegexMethodCalls: true the three methods cannot be read as a value or taken by destructuring either. That also refuses reading a field of ordinary data with one of these names (params.search), so it is off by default. It is for a host where the validator is the only thing between a script and the regular-expression engine; @enclave-vm/core by default runs scripts in a realm where a regular expression cannot run whatever a script does.
Reserved Names
A script cannot declare, assign or use as a property target a name that starts with__ag_ or __safe_, the prefixes of the runtime. reservedPrefixes adds prefixes to those two; it does not replace them. __maxIterations, the runtime’s name for the iteration limit, is reserved as well.
What AgentScript Allows
Default Allowed Globals
The AgentScript preset allows these globals by default (securityLevel: 'STANDARD'):
callTool- Tool invocationMath- Mathematical operationsJSON-JSON.parseandJSON.stringify, as direct calls without a reviver or replacer functionArray- Array constructor and methodsObject- Object methods, used directly (see above)String- String methodsNumber- Number methodsDate- Date operationsundefined,NaN,Infinity- ConstantsparseInt,parseFloat,isNaN,isFinite,encodeURI,decodeURI,encodeURIComponent,decodeURIComponent- Not atSTRICTconsole- Only atPERMISSIVE
getAgentScriptGlobals(securityLevel) returns the list for a level.
Customizing Allowed Globals
Precedence Rules
WhenallowedGlobals and additionalDisallowedIdentifiers are both provided, the following precedence applies:
allowedGlobalsremoves from the dangerous list — If an identifier likeprocessis normally blocked but you include it inallowedGlobals, it will be removed from the built-in dangerous identifiers blocklist and allowed.additionalDisallowedIdentifiersalways wins — If an identifier appears in bothallowedGlobalsandadditionalDisallowedIdentifiers, it remains blocked. This lets you grant broad access while force-blocking specific identifiers.
Loop Configuration
Control which loop types are allowed:Requiring Tool Calls
Ensure scripts actually use tools:Related
- Overview - Getting started
- Pre-Scanner - Layer 0 defense
- Security Rules - Rule reference
- Code Transform - AST transformations