Lambda Code Sandbox
The Lambda Code Sandbox in SmythOS allows agents to execute custom Node.js code securely and scalably using AWS Lambda under the hood. This serverless setup offers isolated, ephemeral runtime environments ideal for integrating custom business logic, API interactions, and complex data processing into your agents.
How It Works
When you use the NodeJS (Serverless) component in a workflow:
- The function is deployed into an AWS Lambda sandbox
- It runs in an isolated, secure container
- The code is cleaned up immediately after execution
- Resources like CPU and memory are automatically allocated
Code Structure and Execution
Your code must be structured as an async JavaScript function. Supported packages include a wide array of popular NPM modules.
import axios from 'axios';
async function main(inputParam1, inputParam2) {
const response = await axios.get('https://example.com/api');
return { result: response.data };
}
- Inputs automatically map to parameters
- Return values are passed to subsequent components
- Errors are logged and available for debugging
Infrastructure Options
You can choose where your code runs:
SmythOS Infrastructure
- Default for all users
- No setup required
- Scales automatically
- Execution billed via SmythOS credits
Custom AWS Infrastructure
Use your own AWS credentials for full control:
- Configure in Vault
- Provide AWS Access Key, Secret, and Region
- No credits consumed on SmythOS
- Full access to your AWS Lambda configuration
Supported Operations
Common uses include:
- Complex data transformations
- API orchestration
- File parsing
- Business rule enforcement
- ML inference (via REST APIs)
Input and Output Handling
Inputs
Supports all major data types:
- String, number, boolean, date
- JSON objects and arrays
- Binary (for files or images)
Inputs are automatically validated and converted where needed.
Outputs
- Returns must be JSON-serializable
- Errors are captured and passed through
- Logs are available for debugging
Performance and Limits
Execution limits depend on infrastructure:
Resource | SmythOS Infra | Custom AWS |
---|---|---|
Max runtime | 15 seconds | AWS-defined |
Memory | Managed auto | User-defined |
CPU | Shared pool | User-defined |
Disk | Temporary only | Temporary only |
For heavy workloads, consider using Custom Storage and Data Spaces to offload data and improve responsiveness.
Best Practices
- Validate and sanitize all inputs
- Use structured, single-responsibility functions
- Avoid unnecessary logging of sensitive data
- Use SmythOS Vault for secrets
- Catch and handle errors gracefully
Debugging and Monitoring
Use the Logs tab on the component to monitor:
- Execution time and memory usage
- Stack traces for uncaught errors
- Output values and retries
Integration With Agents
You can use the Lambda Code Sandbox in:
- Conditional logic nodes
- Data processing branches
- API coordination points
Works seamlessly with: