> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.modbox.run/api-reference/modbox-api/sandboxes/wait-for-sandbox/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.modbox.run/_mcp/server. # Block until a sandbox is ready POST /sandboxes/wait Content-Type: application/json Long-polls until the sandbox accepts traffic or `timeout` seconds elapse. Call this right after `POST /sandboxes/provision`. On timeout the response is `ready: false` rather than an error — always check the field before using the sandbox, and call again to keep waiting. Keep `timeout` below any proxy idle limit on your side. Reference: https://docs.modbox.run/api-reference/modbox-api/sandboxes/wait-for-sandbox ## Authentication - `Authorization` header (bearer token, required) — Bearer authentication of the form `Bearer `, where token is your auth token. ## Request ### Headers - `x-workspace-id` (string, optional, nullable) — UUID of the workspace that scopes this request. List the workspaces you belong to with GET /workspaces. ### Body (application/json) This endpoint expects a WaitRequest. - `task_id` (string, required) — The name used when the sandbox was provisioned. - `timeout` (integer, optional, default: 120) — Seconds to wait before giving up. The call returns `ready: false` on timeout rather than failing. - `poll_interval` (integer, optional, default: 5) — Seconds between readiness checks. ## Response ### 200 Successful Response - `ready` (boolean, required) — True when the sandbox became ready. False means the timeout elapsed first — call again to keep waiting. - `elapsed_seconds` (double, optional, default: 0) — How long the call actually waited. ## Errors ### 401 Unauthorized Error Unauthenticated — the Bearer token is missing or invalid. - `error` (ErrorBody, required) — Machine-readable description of a failure. - `detail` (string, optional, nullable) — DEPRECATED — mirrors 'error.message' for backwards compatibility. Read 'error.code' instead. ### 403 Forbidden Error Forbidden — the caller lacks permission for this resource. - `error` (ErrorBody, required) — Machine-readable description of a failure. - `detail` (string, optional, nullable) — DEPRECATED — mirrors 'error.message' for backwards compatibility. Read 'error.code' instead. ### 404 Not Found Error Not found — no such resource in this workspace. - `error` (ErrorBody, required) — Machine-readable description of a failure. - `detail` (string, optional, nullable) — DEPRECATED — mirrors 'error.message' for backwards compatibility. Read 'error.code' instead. ### 422 Unprocessable Entity Error Validation error — see 'error.details' for the offending fields. - `error` (ErrorBody, required) — Machine-readable description of a failure. - `detail` (string, optional, nullable) — DEPRECATED — mirrors 'error.message' for backwards compatibility. Read 'error.code' instead. ## Types ### ErrorBody Machine-readable description of a failure. - `code` (enum, required) — Stable identifier for this class of failure. Branch on this value instead of parsing 'message'. - Allowed values: `unauthenticated`, `invalid_token`, `invalid_credentials`, `email_not_verified`, `forbidden`, `insufficient_role`, `workspace_required`, `workspace_forbidden`, `workspace_not_found`, `member_not_found`, `sandbox_not_found`, `sandbox_name_conflict`, `sandbox_not_ready`, `provisioning_failed`, `image_not_found`, `image_disabled`, `image_immutable`, `registry_not_found`, `api_key_not_found`, `validation_error`, `not_found`, `conflict`, `rate_limited`, `internal_error`, `upstream_error` - `message` (string, required) — Human-readable explanation of what went wrong. - `hint` (string, optional, nullable) — Concrete next step that is likely to resolve the error. - `docs_url` (string, optional, nullable) — Link to the documentation section for this error code. - `retryable` (boolean, optional, default: false) — True when retrying the identical request may succeed (transient failure). False means the request must change first. - `request_id` (string, optional, nullable) — Correlation id, also returned in the 'X-Request-Id' header. - `details` (list of ErrorDetail, optional, nullable) — Field-level problems, present on validation errors. ### ErrorDetail A single field-level problem, typically from request validation. - `issue` (string, required) — Human-readable description of what is wrong with this field. - `field` (string, optional, nullable) — Dotted path to the offending field, e.g. 'body.task_id'. ## Examples **Request** ```json { "task_id": "agent-session-42" } ``` **Response** ```json { "ready": true, "elapsed_seconds": 0 } ``` **SDK Code** ```python import requests url = "https://api.example.com/sandboxes/wait" payload = { "task_id": "agent-session-42" } headers = { "Authorization": "Bearer ", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://api.example.com/sandboxes/wait'; const options = { method: 'POST', headers: {Authorization: 'Bearer ', 'Content-Type': 'application/json'}, body: '{"task_id":"agent-session-42"}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://api.example.com/sandboxes/wait" payload := strings.NewReader("{\n \"task_id\": \"agent-session-42\"\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "Bearer ") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://api.example.com/sandboxes/wait") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = 'Bearer ' request["Content-Type"] = 'application/json' request.body = "{\n \"task_id\": \"agent-session-42\"\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://api.example.com/sandboxes/wait") .header("Authorization", "Bearer ") .header("Content-Type", "application/json") .body("{\n \"task_id\": \"agent-session-42\"\n}") .asString(); ``` ```php request('POST', 'https://api.example.com/sandboxes/wait', [ 'body' => '{ "task_id": "agent-session-42" }', 'headers' => [ 'Authorization' => 'Bearer ', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://api.example.com/sandboxes/wait"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", "Bearer "); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"task_id\": \"agent-session-42\"\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "Bearer ", "Content-Type": "application/json" ] let parameters = ["task_id": "agent-session-42"] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/sandboxes/wait")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```