JavaScript
JavaScript tools run on a V8 engine with a fresh VM for each execution and no state between calls.
Handler
Section titled “Handler”The main file must be cortexone_function.js and export cortexone_handler:
function cortexone_handler(event, context) { var result = { message: "Hello, World!" }; return { statusCode: 200, body: result };}event is the input payload; context is execution metadata. Return an object with statusCode and body — serialization is automatic.
function cortexone_handler(event, context) { var numbers = event.num; var sum = numbers.reduce(function(a, b) { return a + b; }, 0); return { statusCode: 200, body: { sum: sum, mean: sum / numbers.length } };}Environment and HTTP
Section titled “Environment and HTTP”Read environment variables via process.env. When enabled, fetch() returns a synchronous response object (not a Promise) with status, statusText, body (raw string), and headers:
var response = fetch("https://api.example.com/data");var data = JSON.parse(response.body);Restrictions
Section titled “Restrictions”- No
require()orimport. - No file system access.
- Synchronous only —
async/await, Promises, andsetTimeoutare not supported. - Fresh VM per execution, no persistent state.
Built-ins like JSON, Math, Date, Array, and console.log are available.
Limits
Section titled “Limits”512 MB memory, 300-second runtime, 2.0-core CPU. Unhandled errors return 500; timeouts return 408. You can return non-200 status codes intentionally for validation failures.