Write the code that sets the auto-stop of a sandbox.
Before you start
- You need an API key with the
sandboxes:writescope. See API keys. - Read Create, get, and delete a sandbox and Stop and resume a sandbox first.
How the auto-stop works
Each sandbox has two fields:
At
stopAt, the sandbox stops with a normal stop. The pre-stop script runs, the sandbox saves its files, and the host keeps its memory for 10 minutes. GET /v1/sandboxes/{id} shows the stop in operation, as for a stop that you send. See Stop a sandbox.
Each resume sets a new stopAt: the time of the resume plus stopAfterSeconds.
Set the auto-stop at create
SendstopAfterSeconds with the create, from 60 to 2592000 (30 days):
stopAt:
stopAt in place of stopAfterSeconds, for example "stopAt": "2026-11-16T18:00:00Z". The time must be in the future and within 30 days. Do not send stopAt and stopAfterSeconds in one request. The API answers 400.
Extend the auto-stop
SendPATCH /v1/sandboxes/{id} with a new stopAfterSeconds:
200 with the sandbox.
- The new time counts from the current start of the sandbox, not from the request. If the sandbox already ran for longer, it stops now.
- A
stopAtin thePATCHbody sets the time of the next auto-stop. You can sendstopAtonly when the sandbox iscreating,starting, orrunning. For other states, the API answers409. - A
stopAfterSecondsfor astoppedsandbox applies at the next resume.
Turn off the auto-stop
Sendnull in stopAfterSeconds or in stopAt, at create or with PATCH /v1/sandboxes/{id}:
stopAt and stopAfterSeconds are null, and the sandbox runs until you stop it.
Limits of the trial
In the trial, a sandbox stops on its own within 4 hours of its start.autoStopSeconds in GET /v1/limits shows this limit. A stopAfterSeconds above 14400, a stopAt more than 4 hours after the start, and null answer 400. Each paid plan has no limit. See Trial.