The open-source agent harness - the runtime layer that turns an LLM into a working agent.
fix: redact sandbox keys (#197)
Srajan Asthana1ddb9495ebfc
diff --git a/.github/fern/openapi/openapi.json b/.github/fern/openapi/openapi.jsonindex 324437bfb..3175c8c5f 100644--- a/.github/fern/openapi/openapi.json+++ b/.github/fern/openapi/openapi.json@@ -960,7 +960,7 @@"description": "Daytona authentication credentials.","properties": {"api_key": {- "description": "Daytona API key.",+ "description": "Daytona API key. Responses are redacted; on PUT, a real value sets/rotates and a redacted value keeps the stored key.","minLength": 1,"type": "string"}@@ -6623,7 +6623,7 @@},"/api/v1/settings/sandbox-providers": {"get": {- "description": "The single configured sandbox provider for this tenant.",+ "description": "The single configured sandbox provider for this tenant. `auth.api_key` is redacted.","responses": {"200": {"content": {@@ -6657,7 +6657,7 @@"x-fern-sdk-method-name": "get"},"put": {- "description": "Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration.",+ "description": "Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration. `auth.api_key`: real value sets/rotates; redacted keeps existing (400 if none).","requestBody": {"content": {"application/json": {@@ -6687,7 +6687,7 @@}}},- "description": "Invalid request body."+ "description": "Invalid request body, or redacted API key with no stored secret to keep."}},"summary": "Create or replace the sandbox provider",diff --git a/packages/sdk/.fern/metadata.json b/packages/sdk/.fern/metadata.jsonindex 983b23545..65af9440d 100644--- a/packages/sdk/.fern/metadata.json+++ b/packages/sdk/.fern/metadata.json@@ -28,7 +28,7 @@"streamType": "web","useDefaultRequestParameterValues": true},- "originGitCommit": "8df34ca793fa54137fa08741b27f259def98ab50",+ "originGitCommit": "7d6c22892289e07c6dc2526a5ddad23806cf35ee","originGitCommitIsDirty": true,"invokedBy": "ci","requestedVersion": "0.0.0",diff --git a/packages/sdk/pnpm-lock.yaml b/packages/sdk/pnpm-lock.yamlindex 3e88bc9ff..7e13f9622 100644--- a/packages/sdk/pnpm-lock.yaml+++ b/packages/sdk/pnpm-lock.yaml@@ -159,95 +159,95 @@ packages:'@open-draft/[email protected]':resolution: {integrity: sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==}- '@oxc-project/[email protected]':- resolution: {integrity: sha512-u6JZdLBTLotrNC9Vd6vPssINdzcCzleKAH6EJKImQb7GtYvX5keN2dxkoK44stCc4tffE6QQRtZTXVSzsLUlWA==}+ '@oxc-project/[email protected]':+ resolution: {integrity: sha512-nuhZIOLuI6TFQ32I/WnUx+SCPY7SdSKwgnFHydAuoS1+Z4BRcaP+RRJmGzl9lw+0OFF7UmaESf7KQRXaNLHypg==}- '@rolldown/[email protected]':- resolution: {integrity: sha512-zrJtHDcaZJ1Fp7xf4hNl+7seH9Cn/N5TwLYkhgXREtBwAd/jaqW3uqeHxpDugJLVICWg4eW44kOQEGJ1r6jCGw==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-jHC2cnyKz5xU2fhECtFl8OZ83cYNt13GZQD+0uMJ/X3o+ijmd56okHhTUwxVSHPx1IRVIJEZ1/1pPzeLCU6XKA==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [arm64]os: [android]- '@rolldown/[email protected]':- resolution: {integrity: sha512-ieIiibVCp0tX7TLu2cafoNPv8wJyYi01ekXpbf8q2j7F4rGAhhXb/eQh7ge9DRBY78GwmRQtvjZDux7EDbA8kA==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-Dc5mPD8F5F/FS8i01syd7FTF6yB2fVthH/TRkjwJkzUK6EpoxHtqvZQP5Zwq80/5z19TWYHIg1KOHboCgVx/aQ==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [arm64]os: [darwin]- '@rolldown/[email protected]':- resolution: {integrity: sha512-Zh9tCon19eDXJoihx0rqKhMUlMYqzwj3aPsSuHmI4RWZh62dWUL+DJN4C5YQya5TcQBJU/Fe8+rY0jhXTQITqA==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-fpDm4oBo6SqLvWUYCmFhdde3U9KH2fRNNMeAnAPAIwxRL345xutL0EtEUcuoxsoazdJGv/MuDBQHlCDrtbvqOg==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [x64]os: [darwin]- '@rolldown/[email protected]':- resolution: {integrity: sha512-nGbJWewA1wrXXZiQhjAT5rhibGfns5ZNkDVqxsO6zJ3f3YvpoDNNmGMSbbhLuXKjNScaBJVOAboztAWVespQMg==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-rSJoreDE/HoIzoaib6MTp5jQtCTdMHKIvItAKT/ImS6Y6Ww76oUaeMyp4Vc/fAgd/ehji068IxetHXAnqUwN9A==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [x64]os: [freebsd]- '@rolldown/[email protected]':- resolution: {integrity: sha512-QNniJr5Kml0kDEB98jiDOJjXNroxIIi0IXIbdYzY26Xt1pVbeP62+KnoIZLwirOymX/0jDk/2gI/bNUv7A7OIw==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-/jm8OGHgn7oGaJu3i/qZI9spUGcJ+y/lk43ttQ/iO1tOd9NissG6o97bighBCiL+BKRngmcDuR6ikfwYdJmVuQ==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [arm]os: [linux]- '@rolldown/[email protected]':- resolution: {integrity: sha512-TkqEAcmmvH3I/q4114NB4RVt6241Dao48pF45uLcFGrwAaIn0iITgTAKP/dLjbN0R4buJjGb91+UHSoFmpgIWw==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-tIP06BeD9EqvECBrPZ+sqdPlYrT+aYaAiu1wYziVx5elRK/ftm33JxVDy2bXGbr6J0CrtirCkR87/X5a2euEng==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [arm64]os: [linux]libc: [glibc]- '@rolldown/[email protected]':- resolution: {integrity: sha512-NHqjnxpsndf4MPymxteFAWHHfkTL8HjWh1KB7z23ofZ6QO2euONuxDXjat69dKZRALnGypg8k8SsK8vZJoXv1Q==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-Ql1Q0EQqVThvn9VAVlwNzsUvbSFtCMGjLpRRi4pk5i7NZZ4n5ISiLMjHYtus4VQ2PvkSw24zyaCVsiS+sXPj1w==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [arm64]os: [linux]libc: [musl]- '@rolldown/[email protected]':- resolution: {integrity: sha512-6tbrbwfz5GB9DQ4Jwo6hy9v+vR31xZlvzZ6n5Xut6Hhx5PvrA9q/HsK8KMaYQp063iqZGXwNvZtYNLD7EM/x0w==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-GjbjXD4XXfN19D0LZNbmiCBUoDiRACsYHr0yaIbbn8aFsXjHZifcYqu/W5Er5X2X990WjHXFrxarn5chzItorQ==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [ppc64]os: [linux]libc: [glibc]- '@rolldown/[email protected]':- resolution: {integrity: sha512-oyuXxXmoZHjXC917IAPFAAv4wWAa0cM9afk8nx1+9/jNNOX1uPf8yDA6p7G0RypOfw/X0PQt5IfoquY1um+zSg==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-p5WR0NOwaRmJ/B1b6IjEFLLivwEsf3PrdBIhRbhTCQisbo2SvHHpG4ELB/+FgQNnB88LTOF86upmJmbvZdQ2lw==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [s390x]os: [linux]libc: [glibc]- '@rolldown/[email protected]':- resolution: {integrity: sha512-TytMwF2KVGqP2tgd0I1OY0PAv78dZRAYcF5ssDzjM34SUXCED3uXvSd5+lHoC0bTD6eEdFz7LdQNCO1y0oVk9w==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-4/GyVjmhR+Tc6HLJvwc1sOhPqAZtySiSMesOZyX6JQ5XBxoTDEMKQzvo07NIK6nTon/SivlZqvhzvuVBNQhObQ==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [x64]os: [linux]libc: [glibc]- '@rolldown/[email protected]':- resolution: {integrity: sha512-/E9m3qstrJFVPoULV25mVQblSNExY2+kBsYe4sy0Tn0yOOgJ8wZbZt3KnRbF/XeU2Gl1STKUQnDNTqhIE5MD4A==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-l9eeLsCNvPpmSXUej0etw/J1eqV0Jj1D5G/xG6YTijmE6dkv6E2QezgWbTfQk63v952DPqrjOCoiqxq7Bw0YUQ==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [x64]os: [linux]libc: [musl]- '@rolldown/[email protected]':- resolution: {integrity: sha512-Kr0OcsoQI816i6HOl3vFHpd1K0eZyh76zgfj4c1nTyaTsd5r2Mj1lwM4R90y/qaCfmTn9eHy0SKwi98eitRxug==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-e0F355MSTMm3+UOqtV3L24gFUp2N5m1f8L/7d56deik6va+AXdrt9F8LbzGpeWGWRbZEDq4m8NVnJDeBtf9DZg==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [arm64]os: [openharmony]- '@rolldown/[email protected]':- resolution: {integrity: sha512-hOtMwTqnME+/gJcH/PCZ0wn0zPUjiWOgkHpxbSJpfGKMezHltx1S7/k1SitzVa7Ww2cqrDDaFbZEhcJZO8o+Jw==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-AWLi0uBRYh6QlE7OKhiz+phZC0qwtij2QZmhmOdsLdFn64m7oMpooE9ICE3lhm9xMb4SpDo2WbHcxX1iFLFtqw==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [arm64]os: [win32]- '@rolldown/[email protected]':- resolution: {integrity: sha512-ekcqMMkI2PlhYnfzQnB/cEdYUVVJViWvoUyLrbzgDoi3Snfc1mVBwdnc306ufA5ejy8JSPjT2RlW1nQSjW7efg==}+ '@rolldown/[email protected]':+ resolution: {integrity: sha512-UwSDJOg3dqCAejWdxclJjCsh3Qq4vLYMDxmyHqo1btz3stK2VqgwNd3mm5tuIwzSlGIQ/1H9Hr+Zn09mrezNqQ==}engines: {node: ^20.19.0 || >=22.12.0}cpu: [x64]os: [win32]@@ -733,8 +733,8 @@ packages:resolution: {integrity: sha512-LPRKoHnLKd/r3dVxcwO7vhCW+orkOGj9ViueosEBK6ie89CijnfRlhaDhHq/3Hxu4CkWQtxwlBG0mzTQY6uQjw==}- resolution: {integrity: sha512-rn9wpmxplLf7NLNyCk9FyWh3FM43DbY8jOzCdEPzH7uflhTftRbCEpqi6Ly2osgoU8OwObtmavMbWLaWy4LX7A==}+ resolution: {integrity: sha512-rSr7irW0K7QRWzjdJXqZowkcRdDtjRduh43rBltnVKd0VFq839l1lJoDvGJb6gl7+4rTTCrPWu+YfujUL8Ug7w==}engines: {node: ^20.19.0 || >=22.12.0}hasBin: true@@ -1098,48 +1098,48 @@ snapshots:'@open-draft/[email protected]': {}- '@oxc-project/[email protected]': {}+ '@oxc-project/[email protected]': {}- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true- '@rolldown/[email protected]':+ '@rolldown/[email protected]':optional: true'@rolldown/[email protected]': {}@@ -1548,25 +1548,25 @@ snapshots:dependencies:- '@oxc-project/types': 0.143.0+ '@oxc-project/types': 0.144.0'@rolldown/pluginutils': 1.0.1optionalDependencies:- '@rolldown/binding-android-arm64': 1.2.3- '@rolldown/binding-darwin-arm64': 1.2.3- '@rolldown/binding-darwin-x64': 1.2.3- '@rolldown/binding-freebsd-x64': 1.2.3- '@rolldown/binding-linux-arm-gnueabihf': 1.2.3- '@rolldown/binding-linux-arm64-gnu': 1.2.3- '@rolldown/binding-linux-arm64-musl': 1.2.3- '@rolldown/binding-linux-ppc64-gnu': 1.2.3- '@rolldown/binding-linux-s390x-gnu': 1.2.3- '@rolldown/binding-linux-x64-gnu': 1.2.3- '@rolldown/binding-linux-x64-musl': 1.2.3- '@rolldown/binding-openharmony-arm64': 1.2.3- '@rolldown/binding-win32-arm64-msvc': 1.2.3- '@rolldown/binding-win32-x64-msvc': 1.2.3+ '@rolldown/binding-android-arm64': 1.2.4+ '@rolldown/binding-darwin-arm64': 1.2.4+ '@rolldown/binding-darwin-x64': 1.2.4+ '@rolldown/binding-freebsd-x64': 1.2.4+ '@rolldown/binding-linux-arm-gnueabihf': 1.2.4+ '@rolldown/binding-linux-arm64-gnu': 1.2.4+ '@rolldown/binding-linux-arm64-musl': 1.2.4+ '@rolldown/binding-linux-ppc64-gnu': 1.2.4+ '@rolldown/binding-linux-s390x-gnu': 1.2.4+ '@rolldown/binding-linux-x64-gnu': 1.2.4+ '@rolldown/binding-linux-x64-musl': 1.2.4+ '@rolldown/binding-openharmony-arm64': 1.2.4+ '@rolldown/binding-win32-arm64-msvc': 1.2.4+ '@rolldown/binding-win32-x64-msvc': 1.2.4dependencies:@@ -1671,7 +1671,7 @@ snapshots:lightningcss: 1.33.0picomatch: 4.0.5postcss: 8.5.26- rolldown: 1.2.3+ rolldown: 1.2.4tinyglobby: 0.2.17optionalDependencies:'@types/node': 20.19.43diff --git a/packages/sdk/reference.md b/packages/sdk/reference.mdindex fdfec6aa4..b261f6eb1 100644--- a/packages/sdk/reference.md+++ b/packages/sdk/reference.md@@ -2414,7 +2414,7 @@ await client.settings.modelProviders.upsert({<dl><dd>-The single configured sandbox provider for this tenant.+The single configured sandbox provider for this tenant. `auth.api_key` is redacted.</dd></dl></dd>@@ -2469,7 +2469,7 @@ await client.settings.sandboxProviders.get();<dl><dd>-Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration.+Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration. `auth.api_key`: real value sets/rotates; redacted keeps existing (400 if none).</dd></dl></dd>diff --git a/packages/sdk/src/api/resources/settings/resources/sandboxProviders/client/Client.ts b/packages/sdk/src/api/resources/settings/resources/sandboxProviders/client/Client.tsindex e1c39e1ef..45cdc3a0d 100644--- a/packages/sdk/src/api/resources/settings/resources/sandboxProviders/client/Client.ts+++ b/packages/sdk/src/api/resources/settings/resources/sandboxProviders/client/Client.ts@@ -24,7 +24,7 @@ export class SandboxProvidersClient {}/**- * The single configured sandbox provider for this tenant.+ * The single configured sandbox provider for this tenant. `auth.api_key` is redacted.** @param {SandboxProvidersClient.RequestOptions} requestOptions - Request-specific configuration.*@@ -109,7 +109,7 @@ export class SandboxProvidersClient {}/**- * Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration.+ * Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration. `auth.api_key`: real value sets/rotates; redacted keeps existing (400 if none).** @param {TrueForge.DaytonaSandboxProvider} request* @param {SandboxProvidersClient.RequestOptions} requestOptions - Request-specific configuration.diff --git a/packages/sdk/src/api/types/DaytonaSandboxProviderAuth.ts b/packages/sdk/src/api/types/DaytonaSandboxProviderAuth.tsindex d76d05f26..7071529ba 100644--- a/packages/sdk/src/api/types/DaytonaSandboxProviderAuth.ts+++ b/packages/sdk/src/api/types/DaytonaSandboxProviderAuth.ts@@ -4,6 +4,6 @@* Daytona authentication credentials.*/export interface DaytonaSandboxProviderAuth {- /** Daytona API key. */+ /** Daytona API key. Responses are redacted; on PUT, a real value sets/rotates and a redacted value keeps the stored key. */apiKey: string;}diff --git a/packages/server/src/apis/sandboxProviders.ts b/packages/server/src/apis/sandboxProviders.tsindex c1837285b..e7b910bdc 100644--- a/packages/server/src/apis/sandboxProviders.ts+++ b/packages/server/src/apis/sandboxProviders.ts@@ -3,6 +3,7 @@ import type { ISandboxProviderStore } from '../db/sandboxProviderStore';import type { WithTransaction } from '../db/transaction';import { getSandboxProviderRoute, putSandboxProviderRoute } from '../routes/sandboxProviderRoutes';import type { SandboxProvider } from '../schemas/sandboxProvider';+import { MissingStoredSecretError, resolveStoredSecretValue, toRedactedSecretValue } from '../utils/secretRedaction';import { TENANT_ID } from './sessions';export interface SandboxProvidersRouterDeps<TTransaction> {@@ -10,6 +11,13 @@ export interface SandboxProvidersRouterDeps<TTransaction> {withTransaction: WithTransaction<TTransaction>;}+function redactSandboxProvider(manifest: SandboxProvider): SandboxProvider {+ return {+ ...manifest,+ auth: { api_key: toRedactedSecretValue(manifest.auth.api_key) },+ };+}+/** Admin/settings sandbox provider surface (mounted at /api/v1/settings/sandbox-providers). */export function createSandboxProvidersRouter<TTransaction>(deps: SandboxProvidersRouterDeps<TTransaction>) {const getHandler: RouteHandler<typeof getSandboxProviderRoute> = async c => {@@ -17,16 +25,32 @@ export function createSandboxProvidersRouter<TTransaction>(deps: SandboxProviderif (record === undefined) {return c.json({ error: { message: 'No sandbox provider configured' } }, 404);}- return c.json({ data: record.manifest }, 200);+ return c.json({ data: redactSandboxProvider(record.manifest) }, 200);};const putHandler: RouteHandler<typeof putSandboxProviderRoute> = async c => {- const manifest: SandboxProvider = c.req.valid('json');- const record = await deps.sandboxProviderStore.upsertSandboxProvider({- tenant_id: TENANT_ID,- manifest,- });- return c.json({ data: record.manifest }, 200);+ const incoming: SandboxProvider = c.req.valid('json');+ try {+ const record = await deps.withTransaction(async transaction => {+ const existing = await deps.sandboxProviderStore.getSandboxProviderForUpdate(TENANT_ID, transaction);+ const manifest: SandboxProvider = {+ ...incoming,+ auth: {+ api_key: resolveStoredSecretValue({+ incoming: incoming.auth.api_key,+ existing: existing?.manifest.auth.api_key,+ }),+ },+ };+ return deps.sandboxProviderStore.upsertSandboxProvider({ tenant_id: TENANT_ID, manifest }, transaction);+ });+ return c.json({ data: redactSandboxProvider(record.manifest) }, 200);+ } catch (error) {+ if (error instanceof MissingStoredSecretError) {+ return c.json({ error: { message: 'API key is required' } }, 400);+ }+ throw error;+ }};const router = new OpenAPIHono();diff --git a/packages/server/src/db/postgres/sandbox-provider-store/PostgresSandboxProviderStore.ts b/packages/server/src/db/postgres/sandbox-provider-store/PostgresSandboxProviderStore.tsindex 053a97280..a4d7bde78 100644--- a/packages/server/src/db/postgres/sandbox-provider-store/PostgresSandboxProviderStore.ts+++ b/packages/server/src/db/postgres/sandbox-provider-store/PostgresSandboxProviderStore.ts@@ -36,6 +36,19 @@ export class PostgresSandboxProviderStore implements ISandboxProviderStore<Transreturn row === undefined ? undefined : toRecord(row);}+ async getSandboxProviderForUpdate(+ tenantId: string,+ transaction: Transaction<Database>,+ ): Promise<SandboxProviderRecord | undefined> {+ const row = await transaction+ .selectFrom('sandbox_provider')+ .selectAll()+ .where('tenant_id', '=', tenantId)+ .forUpdate()+ .executeTakeFirst();+ return row ? toRecord(row) : undefined;+ }+async upsertSandboxProvider(input: UpsertSandboxProviderInput,transaction?: Transaction<Database>,diff --git a/packages/server/src/db/sandboxProviderStore.ts b/packages/server/src/db/sandboxProviderStore.tsindex 4ddbe81a2..e32833840 100644--- a/packages/server/src/db/sandboxProviderStore.ts+++ b/packages/server/src/db/sandboxProviderStore.ts@@ -21,6 +21,12 @@ export interface UpsertSandboxProviderInput {export interface ISandboxProviderStore<TTransaction = never> {getSandboxProvider(tenantId: string, transaction?: TTransaction): Promise<SandboxProviderRecord | undefined>;+ /**+ * Load the provider while holding a row lock for the lifetime of `transaction`.+ * Postgres: `SELECT … FOR UPDATE`. SQLite: plain read under a write txn (BEGIN IMMEDIATE).+ * Required before read-modify-write of secrets so concurrent keep/rotate cannot interleave.+ */+ getSandboxProviderForUpdate(tenantId: string, transaction: TTransaction): Promise<SandboxProviderRecord | undefined>;/** Single-row write: creates the provider or replaces the whole manifest. */upsertSandboxProvider(input: UpsertSandboxProviderInput, transaction?: TTransaction): Promise<SandboxProviderRecord>;}diff --git a/packages/server/src/db/sqlite/sandbox-provider-store/SqliteSandboxProviderStore.ts b/packages/server/src/db/sqlite/sandbox-provider-store/SqliteSandboxProviderStore.tsindex 7fe22a766..82d699ef7 100644--- a/packages/server/src/db/sqlite/sandbox-provider-store/SqliteSandboxProviderStore.ts+++ b/packages/server/src/db/sqlite/sandbox-provider-store/SqliteSandboxProviderStore.ts@@ -37,6 +37,21 @@ export class SqliteSandboxProviderStore implements ISandboxProviderStore<Transac.executeTakeFirst();}+ /**+ * SQLite has no row-level FOR UPDATE; the required write transaction (BEGIN IMMEDIATE)+ * serializes concurrent writers so RMW of secrets stays consistent.+ */+ async getSandboxProviderForUpdate(+ tenantId: string,+ transaction: Transaction<Database>,+ ): Promise<SandboxProviderRecord | undefined> {+ return await transaction+ .selectFrom('sandbox_provider')+ .select(recordColumns)+ .where('tenant_id', '=', tenantId)+ .executeTakeFirst();+ }+async upsertSandboxProvider(input: UpsertSandboxProviderInput,transaction?: Transaction<Database>,diff --git a/packages/server/src/routes/sandboxProviderRoutes.ts b/packages/server/src/routes/sandboxProviderRoutes.tsindex 2387f715b..7a4d3ce75 100644--- a/packages/server/src/routes/sandboxProviderRoutes.ts+++ b/packages/server/src/routes/sandboxProviderRoutes.ts@@ -18,7 +18,7 @@ export const getSandboxProviderRoute = createRoute({path: '/',tags: [SANDBOX_PROVIDERS_TAG],summary: 'Get the configured sandbox provider',- description: 'The single configured sandbox provider for this tenant.',+ description: 'The single configured sandbox provider for this tenant. `auth.api_key` is redacted.','x-fern-sdk-group-name': ['settings', 'sandboxProviders'],'x-fern-sdk-method-name': 'get',responses: {@@ -38,7 +38,9 @@ export const putSandboxProviderRoute = createRoute({path: '/',tags: [SANDBOX_PROVIDERS_TAG],summary: 'Create or replace the sandbox provider',- description: 'Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration.',+ description:+ 'Upserts the single sandbox provider for this tenant: creates it or replaces its entire configuration. ' ++ '`auth.api_key`: real value sets/rotates; redacted keeps existing (400 if none).','x-fern-sdk-group-name': ['settings', 'sandboxProviders'],'x-fern-sdk-method-name': 'upsert',request: {@@ -54,7 +56,7 @@ export const putSandboxProviderRoute = createRoute({},400: {content: { 'application/json': { schema: RequestErrorResponseSchema } },- description: 'Invalid request body.',+ description: 'Invalid request body, or redacted API key with no stored secret to keep.',},},});diff --git a/packages/server/src/schemas/sandboxProvider.ts b/packages/server/src/schemas/sandboxProvider.tsindex 77a652635..223649a96 100644--- a/packages/server/src/schemas/sandboxProvider.ts+++ b/packages/server/src/schemas/sandboxProvider.ts@@ -10,7 +10,12 @@ import type { DaytonaSandboxProviderOptions } from '@truefoundry/utils-core/coreconst DaytonaSandboxProviderAuthSchema = z.object({- api_key: z.string().min(1).describe('Daytona API key.'),+ api_key: z+ .string()+ .min(1)+ .describe(+ 'Daytona API key. Responses are redacted; on PUT, a real value sets/rotates and a redacted value keeps the stored key.',+ ),}).strict().openapi('DaytonaSandboxProviderAuth');diff --git a/packages/server/tests/unit/apis/sandboxProviders.test.ts b/packages/server/tests/unit/apis/sandboxProviders.test.tsindex 183b589f4..092267c72 100644--- a/packages/server/tests/unit/apis/sandboxProviders.test.ts+++ b/packages/server/tests/unit/apis/sandboxProviders.test.ts@@ -1,23 +1,31 @@import { createCatalogRouter } from '../../../src/apis/catalog';import { createSandboxProvidersRouter } from '../../../src/apis/sandboxProviders';+import { TENANT_ID } from '../../../src/apis/sessions';import { McpCatalog } from '../../../src/catalog/McpCatalog';import { ModelCatalog } from '../../../src/catalog/ModelCatalog';import { SandboxCatalog } from '../../../src/catalog/SandboxCatalog';import { SkillCatalog } from '../../../src/catalog/SkillCatalog';import { migrateSqliteToLatest } from '../../../src/db/migrateSqlite';+import type { ISandboxProviderStore } from '../../../src/db/sandboxProviderStore';import { createSqliteDb } from '../../../src/db/sqlite/client';import { SqliteSandboxProviderStore } from '../../../src/db/sqlite/sandbox-provider-store/SqliteSandboxProviderStore';+import { toRedactedSecretValue } from '../../../src/utils/secretRedaction';const putBody = {type: 'daytona' as const,snapshot_name: 'trueforge-sandbox-image',- auth: { api_key: 'dtn-test' },+ auth: { api_key: 'dtn-test-secret' },exec_timeout_ms: 60000,auto_stop_interval_in_minutes: 5,auto_archive_interval_in_minutes: 60,auto_delete_interval_in_minutes: 7200,};+const putBodyWire = {+ ...putBody,+ auth: { api_key: toRedactedSecretValue(putBody.auth.api_key) },+};+function putInit(body: unknown): RequestInit {return {method: 'PUT',@@ -26,15 +34,33 @@ function putInit(body: unknown): RequestInit {};}+async function createRouters(): Promise<{+ settingsRouter: ReturnType<typeof createSandboxProvidersRouter>;+ sandboxProviderStore: ISandboxProviderStore;+}> {+ const db = createSqliteDb(':memory:');+ await migrateSqliteToLatest(db);+ const sandboxProviderStore = new SqliteSandboxProviderStore(db);+ return {+ settingsRouter: createSandboxProvidersRouter({+ sandboxProviderStore,+ withTransaction: callback => db.transaction().execute(callback),+ }),+ sandboxProviderStore,+ };+}+describe('sandboxProviders router', () => {let settingsRouter: ReturnType<typeof createSandboxProvidersRouter>;let catalogRouter: ReturnType<typeof createCatalogRouter>;+ let sandboxProviderStore: ISandboxProviderStore;beforeAll(async () => {const db = createSqliteDb(':memory:');await migrateSqliteToLatest(db);+ sandboxProviderStore = new SqliteSandboxProviderStore(db);settingsRouter = createSandboxProvidersRouter({- sandboxProviderStore: new SqliteSandboxProviderStore(db),+ sandboxProviderStore,withTransaction: callback => db.transaction().execute(callback),});catalogRouter = createCatalogRouter({@@ -57,14 +83,17 @@ describe('sandboxProviders router', () => {expect(await response.json()).toEqual({ error: { message: 'No sandbox provider configured' } });});- it('PUT upserts the singleton provider and GET returns it', async () => {+ it('PUT upserts the singleton provider and GET returns redacted auth', async () => {const put = await settingsRouter.request('/', putInit(putBody));expect(put.status).toBe(200);- expect(await put.json()).toEqual({ data: putBody });+ expect(await put.json()).toEqual({ data: putBodyWire });const get = await settingsRouter.request('/');expect(get.status).toBe(200);- expect(await get.json()).toEqual({ data: putBody });+ expect(await get.json()).toEqual({ data: putBodyWire });++ const stored = await sandboxProviderStore.getSandboxProvider(TENANT_ID);+ expect(stored?.manifest).toEqual(putBody);});it('PUT rejects invalid bodies at the Zod layer', async () => {@@ -76,3 +105,89 @@ describe('sandboxProviders router', () => {expect(badType.status).toBe(400);});});++describe('sandbox-provider secret redaction and strict PUT', () => {+ it('PUT create with a redacted api_key returns 400', async () => {+ const { settingsRouter } = await createRouters();+ const response = await settingsRouter.request(+ '/',+ putInit({+ ...putBody,+ auth: { api_key: toRedactedSecretValue(putBody.auth.api_key) },+ }),+ );+ expect(response.status).toBe(400);+ expect(await response.json()).toEqual({ error: { message: 'API key is required' } });+ });++ it('PUT with a redacted api_key keeps the stored secret', async () => {+ const { settingsRouter, sandboxProviderStore } = await createRouters();+ expect((await settingsRouter.request('/', putInit(putBody))).status).toBe(200);++ const redactedKeep = {+ ...putBody,+ snapshot_name: 'other-snapshot',+ exec_timeout_ms: 120000,+ auth: { api_key: toRedactedSecretValue(putBody.auth.api_key) },+ };+ const update = await settingsRouter.request('/', putInit(redactedKeep));+ expect(update.status).toBe(200);+ expect(await update.json()).toEqual({+ data: {+ ...redactedKeep,+ auth: { api_key: toRedactedSecretValue(putBody.auth.api_key) },+ },+ });++ const stored = await sandboxProviderStore.getSandboxProvider(TENANT_ID);+ expect(stored?.manifest).toEqual({+ ...putBody,+ snapshot_name: 'other-snapshot',+ exec_timeout_ms: 120000,+ });+ });++ it('PUT with a different redacted api_key still keeps the stored secret', async () => {+ const { settingsRouter, sandboxProviderStore } = await createRouters();+ expect((await settingsRouter.request('/', putInit(putBody))).status).toBe(200);++ const keep = {+ ...putBody,+ snapshot_name: 'kept-snapshot',+ auth: { api_key: 'oth-***REDACTED***-xxx' },+ };+ const response = await settingsRouter.request('/', putInit(keep));+ expect(response.status).toBe(200);+ expect(await response.json()).toEqual({+ data: {+ ...keep,+ auth: { api_key: toRedactedSecretValue(putBody.auth.api_key) },+ },+ });++ const stored = await sandboxProviderStore.getSandboxProvider(TENANT_ID);+ expect(stored?.manifest).toEqual({+ ...putBody,+ snapshot_name: 'kept-snapshot',+ });+ });++ it('PUT with a real api_key rotates the stored secret', async () => {+ const { settingsRouter, sandboxProviderStore } = await createRouters();+ expect((await settingsRouter.request('/', putInit(putBody))).status).toBe(200);++ const rotatedKey = 'dtn-rotated-key';+ const rotated = { ...putBody, auth: { api_key: rotatedKey } };+ const update = await settingsRouter.request('/', putInit(rotated));+ expect(update.status).toBe(200);+ expect(await update.json()).toEqual({+ data: {+ ...rotated,+ auth: { api_key: toRedactedSecretValue(rotatedKey) },+ },+ });++ const stored = await sandboxProviderStore.getSandboxProvider(TENANT_ID);+ expect(stored?.manifest.auth.api_key).toBe(rotatedKey);+ });+});