Agents can execute JavaScript code using Node.js in their sandboxed workspace. This is useful for working with JSON APIs, building quick prototypes, processing data with JavaScript libraries, and any task where JavaScript is the best fit.
What you can ask agents to do
- "Fetch data from this REST API and format it as a table"
- "Write a Node.js script to process this JSON file"
- "Create a simple Express server that serves this data"
- "Parse this HTML and extract all the links"
- "Transform this data using lodash"
How it works
When an agent runs Node.js code:
- The code executes with
nodein the agent's workspace directory - Standard output and errors are captured
- The result is returned to the agent for use in its response
Agents can install npm packages using the shell tool when needed:
- "Install axios and then fetch data from this API"
- "Use cheerio to scrape this webpage"
Sandbox
All Node.js code runs inside the agent's sandbox. The sandbox controls which files the agent can access, which network destinations it can reach, and how long scripts can run. You configure these restrictions per agent in the agent settings.
When to use Node.js vs. other tools
| Scenario | Best tool |
|---|---|
| Working with JSON APIs | Node.js |
| Async operations and promises | Node.js |
| Frontend prototyping | Node.js |
| Data processing and analysis | Python |
| CSV/XML file parsing | Python |
| System commands (ls, curl, git) | Shell |
Tips
- Specify Node.js if you have a preference. If you don't specify, the agent may choose Python for general scripting tasks. Say "Use Node.js to..." if you want JavaScript.
- Agents can install packages. Just ask: "Install cheerio and parse this HTML."
- Good for API work. Node.js shines when working with REST APIs, webhooks, and JSON data.
Next steps
- Running Python Code. For data processing and analysis.
- Running Shell Commands. For system commands.
- Working with Files. How agents handle file uploads and downloads.