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" });
// Execute a simple command
const result = await box.command({
command: "ls -l"
});
console.log(`Command output: ${result.stdout}`);
console.log(`Command error: ${result.stderr}`);
console.log(`Exit code: ${result.exitCode}`);
// Execute command with timeout
const resultWithTimeout = await box.command({
command: "sleep 10",
timeout: "5s"
});
console.log(`Timeout result: ${JSON.stringify(resultWithTimeout, null, 2)}`);
}
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")
# Execute a simple command
result = box.command(
command="ls -l"
)
print(f"Command output: {result.stdout}")
print(f"Command error: {result.stderr}")
print(f"Exit code: {result.exitCode}")
# Execute command with timeout
result_with_timeout = box.command(
command="sleep 10",
timeout="5s"
)
print(f"Timeout result: {result_with_timeout}")
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/commands \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"command": "ls -l"
}
'{
"exitCode": 0,
"stdout": "total 16\ndrwxr-xr-x 4 user user 4096 Jan 15 10:30 .\ndrwxr-xr-x 3 user user 4096 Jan 15 10:25 ..",
"stderr": ""
}Exec command
Execute a command on a running box. This endpoint allows you to send commands to the box and receive the output
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" });
// Execute a simple command
const result = await box.command({
command: "ls -l"
});
console.log(`Command output: ${result.stdout}`);
console.log(`Command error: ${result.stderr}`);
console.log(`Exit code: ${result.exitCode}`);
// Execute command with timeout
const resultWithTimeout = await box.command({
command: "sleep 10",
timeout: "5s"
});
console.log(`Timeout result: ${JSON.stringify(resultWithTimeout, null, 2)}`);
}
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")
# Execute a simple command
result = box.command(
command="ls -l"
)
print(f"Command output: {result.stdout}")
print(f"Command error: {result.stderr}")
print(f"Exit code: {result.exitCode}")
# Execute command with timeout
result_with_timeout = box.command(
command="sleep 10",
timeout="5s"
)
print(f"Timeout result: {result_with_timeout}")
if __name__ == "__main__":
main()curl --request POST \
--url https://gbox.ai/api/v1/boxes/{boxId}/commands \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"command": "ls -l"
}
'{
"exitCode": 0,
"stdout": "total 16\ndrwxr-xr-x 4 user user 4096 Jan 15 10:30 .\ndrwxr-xr-x 3 user user 4096 Jan 15 10:25 ..",
"stderr": ""
}Authorizations
Enter your API Key in the format: Bearer . Get it from https://gbox.ai
Path Parameters
Box ID
"c9bdc193-b54b-4ddb-a035-5ac0c598d32d"
Body
Command execution request parameters
The command to run
"ls -la"
The environment variables to run the command
{
"PATH": "/usr/bin:/bin",
"NODE_ENV": "production"
}
The working directory of the command. It not provided, the command will be run in the box.config.workingDir directory.
"/home/user/projects"
The timeout of the command. If the command times out, the exit code will be 124. For example: 'timeout 5s sleep 10s' will result in exit code 124.
Supported time units: ms (milliseconds), s (seconds), m (minutes), h (hours) Example formats: "500ms", "30s", "5m", "1h" Default: 30s
"30s"
Response
Result of command execution
Was this page helpful?