Skip to content

fix(sandbox): unique app name for same-name creates in the same second - #127

Merged
bchatelard merged 1 commit into
mainfrom
sandbox-app-name-suffix
Nov 17, 2026
Merged

bchatelard merged 1 commit into
mainfrom
sandbox-app-name-suffix

Conversation

@bchatelard

Copy link
Copy Markdown
Member

Why

Two Sandbox.create() calls with the same name in the same second can fail with 400 name already exists. The
app holding each sandbox is named sandbox-app-<name>-<int(time.time())>, and app names are unique per
organization. Parallel creates hit this, and so do two processes creating sandboxes in one organization, like test
jobs whose examples use fixed names. The JavaScript SDK had the same bug at millisecond resolution and fixed it in
koyeb/koyeb-sandbox-sdk-js#60 .

What changed

  • SandboxSpec.app_payload() names the app sandbox-app-<name>-<suffix>. The suffix is the time in seconds in
    base 36, followed by 4 random characters from secrets.
  • The suffix is still 10 characters until 2038, like the decimal seconds it replaces. Every name that fit the
    64-character app name limit still fits.
  • Two same-name creates in the same second now collide only if their 4 random characters match, about 1 in 1.7
    million.

Behavior change: the app name's suffix is no longer the Unix timestamp. Anything parsing the creation time out
of the app name would need the base-36 decode. The SDK itself never reads it back.

How it was verified

  • New test test_app_name_differs_for_same_name_creates_in_the_same_second. It freezes time.time(), builds 20
    payloads for a 41-character name (the longest that fit before), and checks that all 20 differ, are at most 64
    characters and are valid app names. It fails on main (1 != 20) and passes here.
  • pytest koyeb/sandbox: 650 passed, 8 subtests passed.
  • black --check and flake8 --select=E9,F63,F7,F82 (the CI lint) are clean on both changed files.

The app holding a sandbox was named sandbox-app-<name>-<seconds>. App names
are unique per organization, so two creates with the same name in the same
second (parallel creates, or two processes in one organization) failed with
400 "name already exists". Use the time in base 36 plus 4 random
characters: the same 10 characters as before, so every name that fit the
64-character limit still fits.
@bchatelard
bchatelard marked this pull request as ready for review November 17, 2026 15:10
@bchatelard
bchatelard merged commit 78f66c6 into main Nov 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant