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" });
// 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": ""
}Command
Exec command
Execute a command on a running box. This endpoint allows you to send commands to the box and receive the output
POST
/
boxes
/
{boxId}
/
commands
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" });
// 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
Body
application/json
Command execution request parameters
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
Example:
"30s"
Response
200 - application/json
Result of command execution
Was this page helpful?