Function Tools
Copy page
Create custom JavaScript functions that your agents can execute in secure sandboxes
Function tools allow you to create custom JavaScript functions that agents can execute in secure, isolated sandboxes. Unlike MCP servers that connect to external services, function tools run your own code directly within the agent framework.
Overview
Function tools are perfect for:
- Custom business logic - Implement domain-specific calculations or workflows
- Data processing - Transform, validate, or analyze data using JavaScript
- API integrations - Make HTTP calls to services that don't have MCP servers
- Utility functions - Create reusable helper functions for your agents
Creating Function Tools
Basic Function Tool
Function Tool with Dependencies
Dependencies are automatically detected from your code and use the versions installed in your project:
Pinning Dependency Versions
If you need to pin to specific versions, specify them explicitly:
Built-in Node.js Modules
Function tools have access to Node.js built-in modules:
Input Schema Validation
Function tools use JSON Schema to validate input parameters. This ensures your functions receive properly typed and validated data.
Supported JSON Schema Types
Execution Environment
Function tools run in secure, isolated sandboxes that provide a safe execution environment for your code.
Sandbox Providers
The framework supports multiple sandbox providers:
- Native (default) - Uses Node.js child processes, works in most environments including cloud VMs, Docker, Kubernetes, and traditional hosting
- Vercel - Uses Vercel Sandbox MicroVMs for serverless environments where child process spawning is restricted (Vercel, AWS Lambda, etc.)
The sandbox provider is configured at the application level when deploying. See Deploy to Vercel for serverless deployment configuration.
Runtime Configuration
Configure execution settings in your application:
Security & Isolation
Function tools execute with strong security guarantees:
- Isolated execution - Each function runs in its own sandbox
- No file system access - Cannot read or write outside the sandbox
- Network restrictions - Only through explicitly declared dependencies
- Resource limits - CPU, memory, and execution time constraints enforced
- No state persistence - Functions are stateless between executions
Best Practices
- Keep functions focused - Each function should do one thing well
- Minimize dependencies - Only include packages you actually need
- Handle errors gracefully - Always catch and return meaningful errors
- Test independently - Functions should be testable in isolation
- Document thoroughly - Clear descriptions help agents use tools effectively