Skip to content

Daytona provider setup misreports missing write:snapshots permission as an invalid API key #461

Closed

Description

@keniel13-ui

What happened?

TrueForge 0.1.4 reports a valid, usable Daytona API key as invalid when the key can create/delete sandboxes but does not carry Daytona's separate write:snapshots permission.

I hit this while proving the sandbox path for a TrueForge hackathon project. The same key produced these direct Daytona results:

GET    /api/sandbox                         -> 200
POST   /api/sandbox                         -> 200 (sandbox created)
DELETE /api/sandbox/{id}?force=true         -> 200
GET    /api/snapshots/{missing-name}        -> 404 (authenticated not-found)
POST   /api/snapshots                       -> 403 { "message": "Access denied" }

But a schema-valid request to:

PUT /api/v1/settings/sandbox-providers

returns:

422 Daytona rejected the API key — check the credentials

The credential is not rejected. Its sandbox permission works; snapshot registration is forbidden.

The cause is visible in the 0.1.4 path:

  1. sandbox-provider setup calls provider.buildImage();
  2. DaytonaSandboxProvider.buildImage() registers the bundled image with POST /snapshots when the deterministic snapshot does not exist;
  3. a Daytona 403 is classified by isDaytonaAuthError() alongside 401 and rewritten as a bad-key message.

Daytona's bundled SDK models write:snapshots separately from write:sandboxes, so this is an insufficient-permission result, not invalid authentication.

Reproduction

  1. Create a Daytona API key that can write/delete sandboxes but cannot write snapshots.
  2. Confirm that the key can create and delete a sandbox directly.
  3. Configure a Daytona sandbox provider in TrueForge 0.1.4 with that key.
  4. Observe the 422 bad-credential response.
  5. Send the same snapshot registration request directly and observe the underlying 403 Access denied.

No key value is needed in logs; HTTP status and the redacted error body are sufficient.

Expected behavior

  • Distinguish 401 invalid credential from 403 authenticated but insufficient permission.
  • Name the required Daytona permission (write:snapshots) in the API/UI error, or document it next to the API-key field.
  • Ideally, consider a direct-image fallback when write:sandboxes is available but write:snapshots is not. With the same key, daytona.create({ image: <TrueForge bundled image> }) successfully created a sandbox, executed python -c "print(17*19)" with exit 0/result 323, and deleted it. A local compatibility patch using that path also completed the full TrueForge turn:
truefoundry-system exec call
-> sandbox.created (Daytona)
-> tool.response { success: true, exitCode: 0, result: "323\n" }
-> turn.done / DAYTONA_OK:323

If snapshot registration is intentionally mandatory, the first two bullets still prevent a valid key from being blamed for a missing scope.

Environment

  • TrueForge: 0.1.4, standalone/SQLite
  • @daytona/sdk: 0.204.1 (bundled by TrueForge)
  • Daytona API response version observed: 0.207.0
  • Node.js: 24.14.1
  • npm: 11.11.0
  • macOS

Related but not duplicate: #417 covers missing timeouts on the snapshot-registration request. This report is about permission classification and the forced snapshot-write requirement.

Activity

  1. keniel13-ui commented on Aug 26, 2026

    @keniel13-ui
    Author

    Follow-up: the permission diagnosis is now directly confirmed rather than inferred from the 403.

    GET /api/api-keys/current for the original working-sandbox/failing-snapshot key returned this permission array (key value omitted):

    ["write:sandboxes", "delete:sandboxes"]

    write:snapshots was absent. GET /api/snapshots still returned 200, so snapshot read access was available while snapshot registration was not.

    A replacement key carrying exactly:

    ["write:sandboxes", "delete:sandboxes", "write:snapshots"]

    was then tested against unmodified TrueForge 0.1.4:

    PUT /api/v1/settings/sandbox-providers -> 200
    sandbox.created -> Daytona
    truefoundry-system exec -> python3 -c "print(17*19)"
    tool.response -> success=true, exitCode=0, result="323\n"
    turn.done -> output="323"
    

    The sandbox was deleted afterward. No compatibility patch was involved in this second run.

    That narrows the requested fix: direct-image fallback is optional, but the current 403 mapping should not say the key is invalid. It should report that the authenticated key is missing the required write:snapshots permission, and the settings UI/docs should name that required scope.

  2. thesujai commented on Aug 27, 2026

    @thesujai
    Contributor

    Thanks @keniel13-ui, I agree here. The error should have been a 403 instead of a 422.

    https://github.com/truefoundry/trueforge/blob/main/packages/trueforge/src/apis/sandboxProviders.ts#L107 should have returned the error's message here(if they are readable), else can do a further if for seperating 401 from 403.

    Keeping this open for community contribution

  3. added
    help wanted
    on Aug 27, 2026
  4. ethanstoner commented on Aug 27, 2026

    @ethanstoner
    Contributor

    @thesujai I'd like to pick this up, scoped to the classification fix you described — not the direct-image fallback in the third bullet, which reads as a product decision about whether snapshot registration stays mandatory.

    Confirmed on main. isDaytonaAuthError collapses both statuses into one branch:

    // packages/trueforge/src/sandbox/providerUtils.ts:20
    return error instanceof DaytonaError && (error.statusCode === 401 || error.statusCode === 403);

    so PUT /api/v1/settings/sandbox-providers answers 422 "Daytona rejected the API key — check the credentials" both for an invalid key and for a valid key missing write:snapshots.

    On your suggestion to return the error's message at L107: I'd lean against reflecting Daytona's message verbatim. For this case it is just "Access denied", which does not name the missing scope and so does not actually tell the operator what to fix — and reflecting a third-party error into a response is the pattern already flagged in #422. Splitting the statuses and writing our own message gets the operator the scope name and keeps the upstream body out of the response. Concretely:

    • Split the predicate so 401 (invalid credential) and 403 (authenticated, insufficient permission) are distinguishable.
    • Keep 422 for 401. Return 403 for the forbidden case, naming write:snapshots as the required Daytona permission.
    • Extend tests/unit/apis/sandboxProviders.test.ts to cover the two statuses separately.

    Two things that are your call before I start:

    1. The forbidden case changes response status, 422 → 403. That is what you described, but it is a visible API change, and it edits an existing assertion — 'PUT does not persist config when the build call fails auth' asserts 422 for a DaytonaError(403) today. That test's real subject is the non-persistence, which I'd keep; only the status line moves. If you'd rather the status stay 422 and only the message improve, that's a smaller diff and I'll do that instead.
    2. Name the permission only in the API error, or also next to the API-key field in settings? I'd start with the API error and leave the UI alone unless you want it.

    Could you assign it to me if the scope looks right?

  5. satvik8954 commented on Aug 30, 2026

    @satvik8954

    Ran into this exact issue tonight while building a hackathon project — same 422 "invalid key" response from TrueForge despite the key working fine directly against Daytona's API. Confirms this isn't an isolated case. Thanks for the thorough diagnosis and fix in #477.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions