Skip to main content
The AgentScript preset is purpose-built for validating LLM-generated orchestration code. It’s the default preset used by enclave-vm and provides the strictest validation for AI-generated code.

Basic Usage

Configuration Options

Option Reference

Use requireCallTool: true to ensure AgentScript code actually interacts with tools rather than just performing local computations.

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.
The one function declaration a script may contain is the wrapper the transformer puts around it: the first top-level 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):
A variable of the script that is called Object is not the global and is left alone.

Regular-Expression Methods

AgentScript has no regular expressions: regex literals are refused, and so are match, 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 invocation
  • Math - Mathematical operations
  • JSON - JSON.parse and JSON.stringify, as direct calls without a reviver or replacer function
  • Array - Array constructor and methods
  • Object - Object methods, used directly (see above)
  • String - String methods
  • Number - Number methods
  • Date - Date operations
  • undefined, NaN, Infinity - Constants
  • parseInt, parseFloat, isNaN, isFinite, encodeURI, decodeURI, encodeURIComponent, decodeURIComponent - Not at STRICT
  • console - Only at PERMISSIVE
getAgentScriptGlobals(securityLevel) returns the list for a level.

Customizing Allowed Globals

Precedence Rules

When allowedGlobals and additionalDisallowedIdentifiers are both provided, the following precedence applies:
  1. allowedGlobals removes from the dangerous list — If an identifier like process is normally blocked but you include it in allowedGlobals, it will be removed from the built-in dangerous identifiers blocklist and allowed.
  2. additionalDisallowedIdentifiers always wins — If an identifier appears in both allowedGlobals and additionalDisallowedIdentifiers, it remains blocked. This lets you grant broad access while force-blocking specific identifiers.
Be careful when adding normally-blocked identifiers like process or eval to allowedGlobals. Only do so when the sandbox runtime provides safe wrappers for these APIs.

Loop Configuration

Control which loop types are allowed:
for-in loops are blocked by default because they iterate over prototype properties, which can lead to unexpected behavior and security issues.

Requiring Tool Calls

Ensure scripts actually use tools: