JavaScript
import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
});
async function main() {
const box = await gboxSDK.create({ type: "linux" });
// Run Python code
const pythonResult = await box.runCode({
code: `print("Hello from Python!")`,
language: "python"
});
console.log("Python execution result:");
console.log(`Exit code: ${pythonResult.exitCode}`);
console.log(`Output:\n${pythonResult.stdout}`);
if (pythonResult.stderr) {
console.log(`Errors:\n${pythonResult.stderr}`);
}
}
main();import os
from gbox_sdk import GboxSDK
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# Run Python code
python_result = box.run_code(
code="print('Hello from Python!')",
language="python"
)
print("Python execution result:")
print(f"Exit code: {python_result.exitCode}")
print(f"Output:\n{python_result.stdout}")
if python_result.stderr:
print(f"Errors:\n{python_result.stderr}")
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/run-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "print(\"Hello, World!\")"
}
'{
"exitCode": 0,
"stdout": "Hello, World!\n5",
"stderr": ""
}Run Code
Run code on the box
Executes code inside the specified box. Supports multiple languages (bash, Python, TypeScript) and allows you to configure environment variables, arguments, working directory, and timeouts.
POST
/
boxes
/
{boxId}
/
run-code
JavaScript
import GboxSDK from "gbox-sdk";
const gboxSDK = new GboxSDK({
apiKey: process.env["GBOX_API_KEY"] // This is the default and can be omitted
});
async function main() {
const box = await gboxSDK.create({ type: "linux" });
// Run Python code
const pythonResult = await box.runCode({
code: `print("Hello from Python!")`,
language: "python"
});
console.log("Python execution result:");
console.log(`Exit code: ${pythonResult.exitCode}`);
console.log(`Output:\n${pythonResult.stdout}`);
if (pythonResult.stderr) {
console.log(`Errors:\n${pythonResult.stderr}`);
}
}
main();import os
from gbox_sdk import GboxSDK
def main():
gbox_sdk = GboxSDK(api_key=os.environ["GBOX_API_KEY"])
box = gbox_sdk.create(type="linux")
# Run Python code
python_result = box.run_code(
code="print('Hello from Python!')",
language="python"
)
print("Python execution result:")
print(f"Exit code: {python_result.exitCode}")
print(f"Output:\n{python_result.stdout}")
if python_result.stderr:
print(f"Errors:\n{python_result.stderr}")
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/run-code \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"code": "print(\"Hello, World!\")"
}
'{
"exitCode": 0,
"stdout": "Hello, World!\n5",
"stderr": ""
}Authorizations
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Body
application/json
Request parameters for running code in various languages
Was this page helpful?