Run JavaScript and TypeScript
Set language to javascript or typescript when the code is not Python. The host application can use either AgentBox SDK; the language option controls the kernel inside the sandbox.
mjs
const sandbox = await Sandbox.create("code-interpreter");
try {
const javascript = await sandbox.runCode(
"console.log([1, 2, 3].map(x => x * x))",
{ language: "javascript" },
);
console.log(javascript.logs.stdout.join(""));
const typescript = await sandbox.runCode(
"const value: number = 6 * 7; value",
{ language: "typescript" },
);
console.log(typescript.text);
} finally {
await sandbox.kill();
}JavaScript and TypeScript have their own stateful contexts. Install runtime dependencies with sandbox.commands.run("npm install …"), or put them in a custom template when every sandbox needs the same packages.