Overview

The Run Code feature allows you to execute code in multiple programming languages directly on Gbox.

Supported Languages

LanguageIdentifierDescription
PythonpythonPython 3.x with common packages
TypeScripttypescriptTypeScript with tsx runtime
BashbashBash shell commands

Usage

import GboxSDK from "gbox-sdk";
import * as dotenv from "dotenv";

dotenv.config();

const gboxSDK = new GboxSDK({
  apiKey: process.env["GBOX_API_KEY"],
});

async function main() {
  try {
    // Create a Linux box
    const box = await gboxSDK.create({ type: "linux" });

    // Example 1: Simple Python code execution
    console.log("=== Python Example ===");
    const pythonResult1 = await box.runCode("print('Hello, world!')");
    console.log(pythonResult1);

    // Example 2: Python code with explicit language specification
    const pythonResult2 = await box.runCode({
      code: `print("Hello, world!")`,
      language: "python",
    });
    console.log(pythonResult2);

    // Example 3: TypeScript code execution
    console.log("\n=== TypeScript Examples ===");
    const tsResult1 = await box.runCode({
      code: `console.log("Hello, world!");`,
      language: "typescript",
    });
    console.log(tsResult1);

    // Clean up - terminate the box
    await box.terminate();
    console.log("\n✅ Box terminated successfully");
  } catch (error) {
    console.error("❌ Error:", error);
  }
}

// Run the main function
main();