Sandbox.create and send the same key with every retry. E2B creates at most one sandbox for that key and returns its result to each retry.
Idempotency keys require SDK version
2.60.0 or above.Create a sandbox with an idempotency key
Generate one key for each sandbox you want to create, and store it with the job or request that needs the sandbox. This lets you reuse the key if your process restarts.Idempotency-Key header on this one create request. Other SDK calls don’t send it. AsyncSandbox.create accepts the same idempotency_key argument.
The SDK doesn’t generate keys for you. If you don’t pass a key, Sandbox.create works the same as before.
Key format
- 1 to 255 characters.
- Only lowercase ASCII letters, digits and hyphens (
a-z,0-9,-). A lowercase UUID works, which is whatrandomUUID()andstr(uuid.uuid4())return. - Keys are scoped to your team.
InvalidArgumentError (JavaScript) or raises InvalidArgumentException (Python) without sending the request.
Retry with the same key
When E2B receives a create request with a key it has already seen:- Same key, same parameters, original create finished: E2B doesn’t create another sandbox. It returns the original status and response body. This also applies to errors that retrying can’t fix: every retry returns the same error.
- Same key, same parameters, original create failed temporarily: If E2B marked the failure as safe to retry (
Should-Retry: true), for example when there was temporarily no capacity, E2B runs the create again under the same key. Only one attempt runs at a time. - Same key, different parameters: E2B returns an error and doesn’t create a sandbox. Send exactly the same template and options with every retry.
Errors
E2B returns these errors for requests with an idempotency key. In the SDKs, they come back asSandboxError (JavaScript) or SandboxException (Python) with the status code and the message below.