You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: refresh Sandboxes cookbook and API reference (#26188)
## Summary
Refresh the vendored Sandboxes cookbook and OpenAPI reference from
upstream.
Removes standalone MCP gateway start/stop documentation, imports
upstream authentication and timeout examples, auto-resume readback
guidance, and network-policy selector updates, and regenerates the API
presentation data.
@netlify /ai/sandboxes-api/cookbook/give-a-sandbox-an-mcp-gateway/
Generated by Codex
Copy file name to clipboardExpand all lines: content/manuals/ai/sandboxes-api/cookbook/connect-to-cloud-with-a-bearer-token.md
+20-17Lines changed: 20 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,30 +9,33 @@ params:
9
9
group: "Get started"
10
10
---
11
11
12
-
Choose an authenticator when your application creates its client. The client obtains a credential when its first request needs one, then uses it for requests to Docker Cloud Sandboxes. You need an [installed SDK](https://docs.docker.com/ai/sandboxes-api/install/) and a Docker account with Cloud Sandboxes access.
12
+
Sign in to Docker so your application can create and use Cloud Sandboxes. Before you begin, [install the SDK](https://docs.docker.com/ai/sandboxes-api/install/) and make sure your Docker account has Cloud Sandboxes access.
13
13
14
14
Choose interactive sign-in when running an example yourself. Use a personal access token (PAT) for a service or CI job. If your application already manages Docker access tokens, pass a token or a token provider.
15
15
16
16
## Sign in interactively {#1-sign-in-interactively}
17
17
18
-
The helper creates a client with an OAuth authenticator. Call an SDK method, such as listing sandboxes, to start sign-in. Open the printed verification URL in your browser and enter the displayed code. Sign in to your Docker account and approve the request. The SDK request proceeds when verification succeeds; a denied or expired request fails. The [complete program](run-a-complete-example.md) shows this flow from start to finish.
18
+
Call `const client = await login()` using the function below. It prints a link and a code in your terminal. Open the link in your browser, enter the code, and approve sign-in with your Docker account.
19
19
20
-
The request that starts sign-in also sets its deadline. Pass `{ timeoutMs: 300_000 }` as that call's request options to give yourself five minutes to sign in and complete the request.
20
+
The function waits for sign-in to finish before returning a client you can use to call the API. If you deny sign-in or the verification code expires, it reports an error. Run the program again to get a new code. The [complete program](run-a-complete-example.md) shows how to sign in and create a sandbox.
21
21
22
-
The SDK holds credentials in memory by default and refreshes the access token as later requests need it, while refresh credentials remain valid. Close the client when finished to release SDK-owned resources. This does not delete sandboxes or revoke Docker sign-in.
22
+
The SDK keeps your sign-in details in memory and renews access automatically while your sign-in remains valid. You need to sign in again when you restart the program unless you save these details as described below. Call `await client.close()` when finished. Closing the client does not delete your sandboxes or sign you out of Docker.
23
23
24
24
You can pass the same authenticator to several clients to reuse their sign-in. Closing one client leaves the authenticator usable by the others.
console.log(`Open ${verificationUri} and enter ${userCode}`);
62
66
},
63
67
});
68
+
awaitstoredAuth.getAccessToken();
64
69
returnnewSandboxes({ auth: storedAuth });
65
70
}
66
71
```
@@ -72,9 +77,9 @@ export function loginWithSavedCredentials(path: string) {
72
77
73
78
## Optional: save credentials between runs {#2-optional-save-credentials-between-runs}
74
79
75
-
To avoid signing in each time a Node.js program starts, expand the complete example above and use `loginWithSavedCredentials(path)`. It passes `fileOAuthCredentialStore` to the OAuth authenticator.
80
+
To reuse your sign-in when a Node.js program restarts, expand the complete example above and use `await loginWithSavedCredentials(path)`. Set `path` to the file where you want to save your sign-in details. The function uses saved details when they are still valid, or asks you to sign in again, before returning a client.
76
81
77
-
The file store supports Node.js on POSIX systems, not browsers or Windows. Its file contains plaintext access and refresh credentials: keep it out of source control, use a private directory, and do not share it between processes. For a keychain or secret manager, implement `OAuthCredentialStore` with `load` and `save` instead.
82
+
The file store works in Node.js on systems such as macOS and Linux, but not in browsers or on Windows. The file is not encrypted. Keep it in a private directory, exclude it from source control, and do not share it between running programs. To save sign-in details in a keychain or secret manager instead, implement `OAuthCredentialStore` with `load` and `save`.
78
83
79
84
Remove the stored credentials when your application no longer needs them. Your application owns that removal; closing a client does not remove the file or revoke the credentials.
80
85
@@ -165,8 +170,6 @@ Authentication errors mean the credential is missing, rejected, or expired. Sign
165
170
166
171
When you run commands or transfer files through a sandbox handle, the SDK obtains a credential scoped to that sandbox. You do not need to copy your account token into a second client.
167
172
168
-
The client reuses valid sandbox credentials. Concurrent requests share acquisition only within the same management client and for the same resolved Docker credential, sandbox endpoint and permissions. A later request renews the credential shortly before expiry. Renewal happens when needed, not on a five-minute timer, and does not change a request or stream already in progress.
169
-
170
173
Docker sign-in is separate from an agent's provider credential. To let an agent call its model provider, follow [Use secrets in a sandbox](get-a-stored-secret-into-a-sandbox.md).
171
174
172
175
Next, [run a complete program](run-a-complete-example.md) that signs in and launches a kit.
Copy file name to clipboardExpand all lines: content/manuals/ai/sandboxes-api/cookbook/give-a-sandbox-an-mcp-gateway.md
+35-78Lines changed: 35 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ Use an [authenticated client](connect-to-cloud-with-a-bearer-token.md) and serve
17
17
18
18
Supply the server IDs in the kit's MCP options when creating the sandbox. This makes gateway configuration available when the agent starts. Attach any model-provider secrets the agent needs separately.
19
19
20
-
Use this creation-time path for Cloud Sandboxes. Adding a gateway after creation can be rejected for a governed sandbox; recreating it with MCP configured avoids that limitation.
20
+
To add a gateway to an existing sandbox, recreate the sandboxwith MCP configured. There is no separate gateway start or stop operation.
21
21
22
22
{{< tabs >}}
23
23
{{< tab name="TypeScript" >}}
@@ -65,69 +65,54 @@ export async function launchMcpKit(
65
65
{{< /tab >}}
66
66
{{< /tabs >}}
67
67
68
-
## Alternatively, start a gateway after creation {#2-alternatively-start-a-gateway-after-creation}
68
+
## Read the gateway address {#2-read-the-gateway-address}
69
69
70
-
For an existing sandbox that supports gateway creation, use its MCP collection and wait until the gateway is ready. The sandbox must already have the required Docker credential. If startup is refused, do not assume that retrying will add missing credentials or change its policy configuration.
71
-
72
-
Inspect the returned server list and skipped-server reasons. A ready gateway does not guarantee that every requested server was accepted.
## Read the gateway address {#3-read-the-gateway-address}
105
-
106
-
Get the gateway and use its returned URL only when it is ready. The example checks readiness before returning the URL.
70
+
Read the gateway by its `sandboxes/{sandbox}/mcp-gateway` name. The example waits through provisioning with the SDK's bounded waiter and returns the URL only when ready. A failed gateway or an expired wait returns an error. Supply a timeout appropriate for your application.
107
71
108
72
Keep gateway credentials private. The gateway's address and the published URL of an application inside the sandbox are different endpoints.
Add a server to a ready, writable gateway. Adding a server already present does not add a second copy. A shared gateway attached by URL cannot be modified through this sandbox.
143
128
@@ -169,12 +154,14 @@ export async function addMcpGatewayServer(
169
154
{{< /tab >}}
170
155
{{< /tabs >}}
171
156
172
-
## Complete a server's sign-in {#5-complete-a-server-s-sign-in}
157
+
## Complete a server's sign-in {#4-complete-a-server-s-sign-in}
173
158
174
159
Start authorization for a server that requires user sign-in. Present its authorization URL to the user, then read the authorization resource to check progress. The example performs the start and read calls; your application decides how to display and poll the flow.
175
160
176
161
Only an authorized result means the credential is ready. Keep the authorization identity so a later attempt is not mistaken for completion of an earlier one. Request reauthorization only when you intend a new sign-in.
177
162
163
+
Delete the sandbox when it is no longer needed. Its managed gateway is cleaned up with it; a shared gateway attached by URL remains available to its other users.
164
+
178
165
{{< tabs >}}
179
166
{{< tab name="TypeScript" >}}
180
167
@@ -214,33 +201,3 @@ export async function getMcpAuthorization(
214
201
215
202
{{< /tab >}}
216
203
{{< /tabs >}}
217
-
218
-
## Stop the gateway {#6-stop-the-gateway}
219
-
220
-
Stop the gateway when the sandbox no longer needs its tools. This does not delete the sandbox. Detaching from a shared gateway does not remove that gateway for its other users.
221
-
222
-
Existing agent processes may still hold old connection settings. Plan their restart or reconfiguration when changing the gateway.
Copy file name to clipboardExpand all lines: content/manuals/ai/sandboxes-api/cookbook/let-a-stopped-sandbox-resume-on-demand.md
+17-3Lines changed: 17 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,7 +58,9 @@ export async function createWithAutoResume(
58
58
59
59
## Read the effective setting {#2-read-the-effective-setting}
60
60
61
-
Get the sandbox and inspect the effective automatic-resume value together with its state. This checks what the service recorded; it does not send a request to the application or prove that the application can start.
61
+
Get the sandbox and inspect the effective lifecycle automatic-resume value together with its state. The example falls back to the timeout value for older responses and reports an error if neither value is present. An absent value is unknown, not disabled.
62
+
63
+
This checks what the service recorded; it does not send a request to the application or prove that the application can start. Authentication is still required.
62
64
63
65
To verify the whole flow, stop the sandbox, request its published application URL, and confirm that the application becomes ready. Allow for startup time and keep the application's own authentication enabled.
64
66
@@ -67,8 +69,14 @@ To verify the whole flow, stop the sandbox, request its published application UR
Copy file name to clipboardExpand all lines: content/manuals/ai/sandboxes-api/cookbook/run-a-complete-example.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,9 +17,13 @@ Run a small program that signs in to Docker, creates a sandbox from the `shell`
17
17
18
18
Expand the complete example and copy the whole program into a file. Save it as `example.mts`, then run `npx tsx example.mts`.
19
19
20
-
The program prints a verification URL and code when its first API request needs authentication. Open the URL, enter the code, and approve sign-in. Your terminal then shows the sandbox's name and `Hello from Docker Sandboxes`. The program checks the command's exit status and cleans up its sandbox before closing the client.
20
+
The program prints a verification URL and code. Open the URL, enter the code, and approve sign-in. Your terminal then shows the sandbox's name and `Hello from Docker Sandboxes`. The program checks the command's exit status and attempts to delete its sandbox before closing the client.
21
21
22
-
If authentication fails, check the steps in [Authenticate to Docker](connect-to-cloud-with-a-bearer-token.md). If creation is refused, check account access and [resource limits](work-within-the-limits.md). A timeout does not prove that an accepted sandbox was deleted; keep any sandbox name reported with a cleanup error so you can inspect it.
22
+
The program waits for sign-in to finish or the verification code to expire. After sign-in, creating the sandbox and running the command share a five-minute time limit. Once the program receives the new sandbox's details, it allows another 30 seconds to delete that sandbox, even if a later step fails.
23
+
24
+
If sign-in fails, follow the steps in [Authenticate to Docker](connect-to-cloud-with-a-bearer-token.md). If sandbox creation fails, check account access and [resource limits](work-within-the-limits.md).
25
+
26
+
A creation timeout can occur after Docker creates the sandbox but before the program receives its details. In that case, the program cannot delete it. [List your sandboxes](page-through-and-filter-lists.md) to check for a sandbox created by this run and [delete it](delete-a-cloud-sandbox.md) if needed. If deletion fails or times out, use the sandbox name printed in your terminal to check whether it still exists.
23
27
24
28
This example deletes its sandbox because it is a one-off demonstration. Next, [keep a sandbox for later work](create-your-first-sandbox.md) or [run an agent kit](add-tools-with-kits.md).
0 commit comments