Skip to main content
CodeCall AgentScript example AgentScript is the safe JavaScript subset that runs inside codecall:execute. It gives LLMs the power to orchestrate multiple tools, filter data, and build workflows — while the security pipeline ensures every script is validated, transformed, and sandboxed before execution.

Core APIs

callTool(name, input, options?)

Call a registered tool and get the result.
Parameters: Options: Return value (when throwOnError: false):

getTool(name)

Get metadata about a tool (name, description, schemas) without calling it.

codecallContext

Read-only context object passed in the codecall:execute request. Use it to access tenant information, user IDs, or any custom data.

console (if enabled)

Standard console methods, captured in the response logs array.
Console is only available if vm.allowConsole: true in plugin config. Logs are returned in the logs array of the response.

__safe_parallel(fns, options?)

Execute multiple async operations in parallel with controlled concurrency.
Options: Limits: Error behavior: If any operation fails, the entire __safe_parallel call fails with a combined error message.

What You Can Write

AgentScript supports a safe subset of JavaScript:

What Is Blocked

Dynamic code execution is blocked to prevent injection attacks.
Module loading is blocked to prevent sandbox escape.
No access to Node.js globals or the host environment.
Unbounded loops are blocked to prevent infinite execution.
Use for-of or for with bounds instead.
Prototype manipulation is blocked to prevent pollution attacks.
Identifiers starting with __ag_ or __safe_ are reserved for the runtime.
Async escape via timers is blocked.
In AgentScript’s strict mode, regex literals are blocked to prevent ReDoS.

Error Handling Patterns

Basic: throwOnError

Retry Pattern

Fallback Pattern

Partial Success Pattern


Parallel Execution

Use __safe_parallel for concurrent operations:

Batch Fetching

Parallel Aggregation


Best Practices

Keep scripts focused. Each script should do one logical operation. Break complex workflows into separate codecall:execute calls rather than writing mega-scripts.
Paginate large datasets. Don’t fetch everything at once. Use limit and offset parameters, and filter server-side.
Use throwOnError: false for optional operations. When a failure in one tool call shouldn’t abort the entire script, use the safe pattern.
Return only what you need. Filter and transform data inside the script so the LLM receives a minimal, focused result instead of raw tool output.

Next Steps

API Reference

Complete meta-tool schemas, error codes, and debugging guide

Examples & Recipes

Real-world patterns built with AgentScript

Security Model

How AgentScript is validated, transformed, and sandboxed

Configuration

VM presets, iteration limits, and console settings