Documentation
JavaScript / TypeScript: run code
Run a file or snippet without creating a persistent sandbox. Results use the same submission format as the HTTP API.
Before you run it
Follow the SDK quickstart to install the package and set BOLTZLABS_API_KEY.
Run code or a local file
import { execute, languages } from 'boltzlabs';
console.log(String(await execute('console.log(40 + 2)', { language: 'node' })));
console.log(String(await execute({ file: 'main.ts', language: 'typescript' })));
console.log(String(await execute('print(sum(range(101)))', { language: 100 })));
console.log(await languages()); // ids, codes and names from the platformSpecify the language explicitly; it is not inferred from the file extension. The SDK runs on Node.js and can submit any supported language.
Read the result
const result = await execute({ file: 'main.ts', language: 'typescript' });
console.log(String(result));
console.log(result.ok); // true when Accepted
console.log(result.status.description);
console.log(result.time); // CPU seconds
console.log(result.wall_time); // wall seconds
console.log(result.memory); // peak memory in KB
console.log(result.stdout, result.stderr, result.compile_output);
console.log(result.exit_code, result.message);
console.log(result.json); // whole response
result.check(); // throws unless AcceptedProgram failures are results. Compiled languages, including TypeScript, build first; compilation
failures return status Compilation Error with details in compile_output.
Judge a solution
const result = await execute({
file: 'solution.py',
language: 'python',
stdin: '3\n1 2 3\n',
expected_output: '6',
cpu_time_limit: 1, // seconds
memory_limit: 65536, // KB
});
console.log(result.status.description); // Accepted, Wrong Answer, ...Limits only lower the platform limits. Output comparison ignores trailing spaces on each line and trailing blank lines.
Run test cases together
Batch submission is available to paid users. Waiting defaults to 21 minutes to allow workers to
start; set timeoutMs to override.
import { readFile } from 'node:fs/promises';
import { executeBatch } from 'boltzlabs';
const code = await readFile('solution.py', 'utf8');
const tests = [['1 2\n', '3'], ['5 5\n', '10'], ['0 0\n', '0']];
const results = await executeBatch(tests.map(([stdin, expected_output]) => ({
code, language: 'python', stdin, expected_output, cpu_time_limit: 1,
}))); // up to 20 submissions, results returned in input order
console.log(results.map((result) => result.status.description));What a run counts against
One submission is one request; each batch entry counts separately. Free accounts get 50 requests a day. Monthly plans have no daily limit and run as many requests as their allowance covers. See Run code pricing.