Wait for Command
curl --request GET \
--url https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait"
headers = {"X-API-Key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-API-Key': '<api-key>'}};
fetch('https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait', 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.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"stdout": "<string>",
"stderr": "<string>",
"exit_code": 123
}Command API
Wait for Command
Block until a background command completes and return its result.
GET
/
sandboxes
/
{sandbox_id}
/
commands
/
{pid}
/
wait
Wait for Command
curl --request GET \
--url https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait \
--header 'X-API-Key: <api-key>'import requests
url = "https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait"
headers = {"X-API-Key": "<api-key>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {'X-API-Key': '<api-key>'}};
fetch('https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait', 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.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"X-API-Key: <api-key>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("X-API-Key", "<api-key>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait")
.header("X-API-Key", "<api-key>")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.declaw.ai/sandboxes/{sandbox_id}/commands/{pid}/wait")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
request["X-API-Key"] = '<api-key>'
response = http.request(request)
puts response.read_body{
"stdout": "<string>",
"stderr": "<string>",
"exit_code": 123
}Blocks until the background process identified by
pid completes, then returns the
full CommandResult. The process is removed from the tracked list after this call
returns.
If the PID is not found in the tracked process list, the endpoint returns a
CommandResult with exit_code: 1 and a "process not found" message in stderr.
Path Parameters
string
required
The sandbox identifier. Format:
sbx-<8 chars>.integer
required
Process ID of the background command to wait for.Example:
42Response
string
Full standard output produced by the command.
string
Full standard error output. Contains
"process not found" if the PID is
not tracked.integer
Exit code returned by the process.
0 indicates success. 1 when the
process was not found.Example
# Start a background command first
curl -X POST https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/commands \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "cmd": "sleep 2 && echo done", "background": true }'
# Then wait for it
curl https://api.declaw.ai/sandboxes/sbx-a1b2c3d4/commands/42/wait \
-H "X-API-Key: YOUR_API_KEY"
from declaw import Sandbox
sbx = Sandbox.connect("sbx-a1b2c3d4", api_key="YOUR_API_KEY", domain="api.declaw.ai")
handle = sbx.commands.run("sleep 2 && echo done", background=True)
result = sbx.commands.wait(handle.pid)
print(result.stdout) # done\n
print(result.exit_code) # 0
import { Sandbox } from "@declaw/sdk";
const sbx = await Sandbox.connect("sbx-a1b2c3d4", {
apiKey: "YOUR_API_KEY",
domain: "api.declaw.ai",
});
const handle = await sbx.commands.run("sleep 2 && echo done", {
background: true,
});
const result = await sbx.commands.wait(handle.pid);
console.log(result.stdout); // done\n
console.log(result.exitCode); // 0
Response
{
"stdout": "done\n",
"stderr": "",
"exit_code": 0
}
Error Responses
| Status | Cause |
|---|---|
400 | pid path parameter is not a valid integer |
401 | Missing or invalid API key |
503 | Sandbox has no VM |
502 | envd daemon inside the VM is unreachable |