Basic Usage
Transformation Output
Transformation Options
| Option | Type | Default | Description |
|---|---|---|---|
wrapInMain | boolean | true | Wrap code in async function __ag_main() |
transformCallTool | boolean | true | Transform callTool to safe proxy |
transformLoops | boolean | true | Transform loops with iteration limits |
transformConsole | boolean | true | Transform console to rate-limited proxy |
prefix | string | '__safe_' | Prefix for safe runtime functions |
Main Wrapper
The main wrapper enables top-level await and provides an entry point:__ag_main() to execute the script.
Safe callTool
ThecallTool transformation proxies all tool calls through the runtime:
__safe_callTool proxy:
- Counts tool calls against
maxToolCallslimit - Routes calls through the configured
toolHandler - Sanitizes arguments and return values
Safe Loops
Loop transformations enforce iteration limits:Safe Console
Console methods are proxied for rate limiting:__safe_console proxy:
- Counts calls against
maxConsoleCalls - Tracks output bytes against
maxConsoleOutputBytes - Captures output for streaming to clients
Reserved Prefixes
The transformation reserves these prefixes that user code cannot use:__ag_- AgentScript internal identifiers__safe_- Safe runtime proxies
ReservedPrefixRule.
Custom Transformation
For advanced use cases, you can customize transformations:Integration with enclave-vm
enclave-vm automatically applies transformations whentransform: true (default):
Transformation Without Validation
You can transform code independently of validation:Related
- Overview - Getting started
- AgentScript Preset - Preset configuration
- enclave-vm - Runtime sandbox