Run a command in a sandbox
Starts a command inside a running sandbox and returns the exec at once: running, or exited with its exit_code if it already finished. It doesn’t wait for the command or stream its output: attach to the exec’s WebSocket for its output and stdin, or wait for the exit code with GET /ai/sandboxes/{sandbox_id}/execs/{exec_id}?wait=….
If the sandbox can’t confirm the start within a few seconds (it may still be starting up), the exec comes back starting, and the start completes in the background: follow it with GET /ai/sandboxes/{sandbox_id}/execs/{exec_id}. A start that can’t be confirmed within 5 minutes ends failed with reason agent_unavailable.
The process keeps running when you disconnect. It uses the sandbox’s working directory and environment unless you override them.
Send an Idempotency-Key: a retry with the same key returns the same exec instead of starting the command twice, and completes a start that was still starting.
curl --request POST \
--url https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"command": [
"python",
"evaluate.py",
"--split",
"test"
],
"env": {
"LOG_LEVEL": "info"
},
"workdir": "/app",
"timeout": 3600
}
'import requests
url = "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs"
payload = {
"command": ["python", "evaluate.py", "--split", "test"],
"env": { "LOG_LEVEL": "info" },
"workdir": "/app",
"timeout": 3600
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
command: ['python', 'evaluate.py', '--split', 'test'],
env: {LOG_LEVEL: 'info'},
workdir: '/app',
timeout: 3600
})
};
fetch('https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'command' => [
'python',
'evaluate.py',
'--split',
'test'
],
'env' => [
'LOG_LEVEL' => 'info'
],
'workdir' => '/app',
'timeout' => 3600
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs"
payload := strings.NewReader("{\n \"command\": [\n \"python\",\n \"evaluate.py\",\n \"--split\",\n \"test\"\n ],\n \"env\": {\n \"LOG_LEVEL\": \"info\"\n },\n \"workdir\": \"/app\",\n \"timeout\": 3600\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"command\": [\n \"python\",\n \"evaluate.py\",\n \"--split\",\n \"test\"\n ],\n \"env\": {\n \"LOG_LEVEL\": \"info\"\n },\n \"workdir\": \"/app\",\n \"timeout\": 3600\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"command\": [\n \"python\",\n \"evaluate.py\",\n \"--split\",\n \"test\"\n ],\n \"env\": {\n \"LOG_LEVEL\": \"info\"\n },\n \"workdir\": \"/app\",\n \"timeout\": 3600\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "exec-0192f1c9-3e2a-7b1d-8c4f-5a6b7c8d9e0f",
"sandbox_id": "sb-0192f1c2-7a4b-7c3e-9d1e-2f3a4b5c6d7e",
"command": [
"python",
"evaluate.py",
"--split",
"test"
],
"env": {
"LOG_LEVEL": "info"
},
"workdir": "/app",
"timeout": 3600,
"status": "running",
"exit_code": null,
"reason": null,
"created_at": "2026-11-13T10:05:00Z",
"finished_at": null
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "Input should be greater than or equal to 1.",
"source": {
"pointer": "/timeout"
}
}
]
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "Could not find any usable credentials in the request."
}
]
}{
"errors": [
{
"title": "sandboxes_not_whitelisted",
"detail": "The organization isn't whitelisted."
}
]
}{
"errors": [
{
"code": "10005",
"title": "Resource not found",
"detail": "Sandbox not found."
}
]
}{
"errors": [
{
"title": "sandbox_not_running",
"detail": "The sandbox isn't running."
}
]
}{
"errors": [
{
"title": "invalid_command",
"detail": "The command has more than 4096 arguments."
}
]
}{
"errors": [
{
"code": "10037",
"title": "Service unavailable",
"detail": "A dependency can't answer right now; retry later."
}
]
}Authorizations
Headers
Optional client-chosen key (e.g. a UUID, at most 255 characters) that makes the call safe to retry. Within 24 h, the same key with the same request returns the stored response instead of acting twice; the same key with a different request fails with idempotency_key_reused; a request with a key that's still being processed fails with request_in_progress.
1 - 255Body
A command to run in a running sandbox.
Was this page helpful?
curl --request POST \
--url https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"command": [
"python",
"evaluate.py",
"--split",
"test"
],
"env": {
"LOG_LEVEL": "info"
},
"workdir": "/app",
"timeout": 3600
}
'import requests
url = "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs"
payload = {
"command": ["python", "evaluate.py", "--split", "test"],
"env": { "LOG_LEVEL": "info" },
"workdir": "/app",
"timeout": 3600
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
command: ['python', 'evaluate.py', '--split', 'test'],
env: {LOG_LEVEL: 'info'},
workdir: '/app',
timeout: 3600
})
};
fetch('https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'command' => [
'python',
'evaluate.py',
'--split',
'test'
],
'env' => [
'LOG_LEVEL' => 'info'
],
'workdir' => '/app',
'timeout' => 3600
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs"
payload := strings.NewReader("{\n \"command\": [\n \"python\",\n \"evaluate.py\",\n \"--split\",\n \"test\"\n ],\n \"env\": {\n \"LOG_LEVEL\": \"info\"\n },\n \"workdir\": \"/app\",\n \"timeout\": 3600\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"command\": [\n \"python\",\n \"evaluate.py\",\n \"--split\",\n \"test\"\n ],\n \"env\": {\n \"LOG_LEVEL\": \"info\"\n },\n \"workdir\": \"/app\",\n \"timeout\": 3600\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/ai/sandboxes/{sandbox_id}/execs")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"command\": [\n \"python\",\n \"evaluate.py\",\n \"--split\",\n \"test\"\n ],\n \"env\": {\n \"LOG_LEVEL\": \"info\"\n },\n \"workdir\": \"/app\",\n \"timeout\": 3600\n}"
response = http.request(request)
puts response.read_body{
"data": {
"id": "exec-0192f1c9-3e2a-7b1d-8c4f-5a6b7c8d9e0f",
"sandbox_id": "sb-0192f1c2-7a4b-7c3e-9d1e-2f3a4b5c6d7e",
"command": [
"python",
"evaluate.py",
"--split",
"test"
],
"env": {
"LOG_LEVEL": "info"
},
"workdir": "/app",
"timeout": 3600,
"status": "running",
"exit_code": null,
"reason": null,
"created_at": "2026-11-13T10:05:00Z",
"finished_at": null
}
}{
"errors": [
{
"code": "10015",
"title": "Bad Request",
"detail": "Input should be greater than or equal to 1.",
"source": {
"pointer": "/timeout"
}
}
]
}{
"errors": [
{
"code": "10009",
"title": "Authentication failed",
"detail": "Could not find any usable credentials in the request."
}
]
}{
"errors": [
{
"title": "sandboxes_not_whitelisted",
"detail": "The organization isn't whitelisted."
}
]
}{
"errors": [
{
"code": "10005",
"title": "Resource not found",
"detail": "Sandbox not found."
}
]
}{
"errors": [
{
"title": "sandbox_not_running",
"detail": "The sandbox isn't running."
}
]
}{
"errors": [
{
"title": "invalid_command",
"detail": "The command has more than 4096 arguments."
}
]
}{
"errors": [
{
"code": "10037",
"title": "Service unavailable",
"detail": "A dependency can't answer right now; retry later."
}
]
}