@cdbx.ai/run
v0.1.1
Published
TypeScript SDK for the cdbx Runner API — execute code in a secure sandbox
Maintainers
Readme
@cdbx.ai/run
TypeScript SDK for the cdbx Runner API — execute code in a secure sandbox from any Node.js or browser environment.
Install
npm install @cdbx.ai/run
# or
pnpm add @cdbx.ai/runUsage
import { CdbxRunner } from '@cdbx.ai/run';
const runner = new CdbxRunner({ apiKey: 'cdbx_your_key_here' });
const { stdout, stderr, exitCode, durationMs } = await runner.run({
language: 'python',
code: 'print("Hello, world!")',
});
console.log(stdout); // "Hello, world!\n"Convenience function
import { run } from '@cdbx.ai/run';
const result = await run('cdbx_your_key_here', {
language: 'typescript',
code: 'console.log("Hello from TypeScript!")',
});With stdin
const result = await runner.run({
language: 'python',
code: 'name = input()\nprint(f"Hello, {name}!")',
stdin: 'world',
});With timeout
const result = await runner.run({
language: 'python',
code: 'import time; time.sleep(5)',
timeout: 3, // seconds — capped by your tier
});Error handling
import { CdbxRunner, AuthError, QuotaExceededError, CdbxRunnerError } from '@cdbx.ai/run';
try {
const result = await runner.run({ language: 'python', code: '...' });
} catch (err) {
if (err instanceof AuthError) {
// Invalid or missing API key
} else if (err instanceof QuotaExceededError) {
// Monthly quota exhausted — err.retryAfter is seconds until reset
console.log(`Retry after ${err.retryAfter}s`);
} else if (err instanceof CdbxRunnerError) {
// Other API error — err.status is the HTTP status code
}
}Rate limit headers
Every successful response includes quota info:
const { rateLimit } = await runner.run({ language: 'python', code: '...' });
if (rateLimit) {
console.log(`${rateLimit.remaining} / ${rateLimit.limit} executions remaining`);
}Supported languages
30 languages including Python, JavaScript, TypeScript, Go, Rust, Java, C, C++, Ruby, PHP, Swift, and more. Full list in the API docs.
API key
Generate a key at cdbx.ai → Developer → API Keys. Select the Runner API scope.
License
MIT
