The open-source agent harness - the runtime layer that turns an LLM into a working agent.
feat: upload TFY sandbox files without stuffing them onto exec argv (#786)
Bhavesh Patele5e651cd48cd
diff --git a/.changeset/tfy-sandbox-upload-api.md b/.changeset/tfy-sandbox-upload-api.mdnew file mode 100644index 000000000..be742d5d3--- /dev/null+++ b/.changeset/tfy-sandbox-upload-api.md@@ -0,0 +1,5 @@+---+"@truefoundry/trueforge-core": patch+---++Upload TFY sandbox files via POST /files/upload so large files are not stuffed onto exec argv.diff --git a/charts/trueforge/Chart.lock b/charts/trueforge/Chart.lockindex 468ccc306..958400dd6 100644--- a/charts/trueforge/Chart.lock+++ b/charts/trueforge/Chart.lock@@ -7,6 +7,6 @@ dependencies:version: 24.0.0- name: tfy-sandbox-serverrepository: oci://tfy.jfrog.io/tfy-helm- version: 0.3.3-digest: sha256:4a1e8e592add0094b94177b0e5deea17ccec1efc034e4399176a9421e8fca0a7-generated: "2026-09-17T18:47:27.221049+05:30"+ version: 0.3.4+digest: sha256:6907545c404a1c892aad13e017c6fc1a6fc813287f6c18eda8666312b2c976ed+generated: "2026-09-21T16:44:28.85081+05:30"diff --git a/charts/trueforge/Chart.yaml b/charts/trueforge/Chart.yamlindex 08b90abc0..173e71de9 100644--- a/charts/trueforge/Chart.yaml+++ b/charts/trueforge/Chart.yaml@@ -30,7 +30,7 @@ dependencies:condition: redis.enabled# Dev sandbox server, deployed only when a parent chart enables it.- name: tfy-sandbox-server- version: "0.3.3"+ version: "0.3.4"repository: oci://tfy.jfrog.io/tfy-helmcondition: truefoundry.devSandboxServerEnabledalias: tfy-sandbox-serverdiff --git a/packages/trueforge-core/src/core/sandbox/provider/TFYSandboxProvider.ts b/packages/trueforge-core/src/core/sandbox/provider/TFYSandboxProvider.tsindex 7544eba18..101365649 100644--- a/packages/trueforge-core/src/core/sandbox/provider/TFYSandboxProvider.ts+++ b/packages/trueforge-core/src/core/sandbox/provider/TFYSandboxProvider.ts@@ -16,7 +16,6 @@ import {} from '../SandboxErrors';import { absolutizeRelativeExecEnv } from './execEnv';import {- ensureExecSuccess,shellEscape,type ExecResult,type SandboxBuild,@@ -29,6 +28,9 @@ const DEFAULT_TIMEOUT_SECONDS = 60;// Buffer for network latency + response processing on top of the server-side timeout.const CLIENT_TIMEOUT_BUFFER_SECONDS = 5;+// TFY sandbox file upload timeout (same as Daytona SDK uploadFile default timeout).+const FILE_UPLOAD_TIMEOUT_MS = 30 * 60 * 1000;+const TFY_MCP_CLIENT_BIN = 'mcp-client/bin';/** Put the layout CLI first on PATH (cwd-relative; {@link absolutizeRelativeExecEnv} makes it absolute). */@@ -228,14 +230,27 @@ export class TFYSandboxProvider implements SandboxProvider {}async uploadFile(params: { sandboxId: string; remotePath: string; content: Buffer }): Promise<void> {- const encoded = params.content.toString('base64');- const escapedPath = shellEscape(params.remotePath);+ validateSandboxOwnedByTenant({ sandboxId: params.sandboxId, tenantName: this.tenantName });- const result = await this.exec({- sandboxId: params.sandboxId,- command: `echo ${shellEscape(encoded)} | base64 -d > ${escapedPath}`,+ return context.with(suppressTracing(context.active()), async () => {+ const query = new URLSearchParams({ sandbox_id: params.sandboxId, path: params.remotePath });+ const response = await fetch(`${this.serverUrl}/files/upload?${query.toString()}`, {+ method: 'POST',+ headers: { 'Content-Type': 'application/octet-stream' },+ body: params.content,+ signal: AbortSignal.timeout(FILE_UPLOAD_TIMEOUT_MS),+ });+ if (!response.ok) {+ throw new Error(+ `File upload to sandbox failed: Sandbox server returned ${String(response.status)}: ${await response.text()}`,+ );+ }++ const result = (await response.json()) as { success: true } | { success: false; error: string };+ if (!result.success) {+ throw new Error(`File upload to sandbox failed: ${result.error}`);+ }});- ensureExecSuccess(result);}// The TFY sandbox exposes a static, cluster-internal NATS WebSocket URL (no signed URLs).diff --git a/packages/trueforge-core/tests/core/sandbox/provider/tfyUpload.test.ts b/packages/trueforge-core/tests/core/sandbox/provider/tfyUpload.test.tsnew file mode 100644index 000000000..4ee6e0ce3--- /dev/null+++ b/packages/trueforge-core/tests/core/sandbox/provider/tfyUpload.test.ts@@ -0,0 +1,73 @@+import { TFYSandboxProvider } from '../../../../src/core/sandbox/provider/TFYSandboxProvider';+import { makeSilentLogger } from '../../harnessMocks';++const SERVER_URL = 'http://sandbox.example';+const SANDBOX_ID = 'acme.00000000-0000-0000-0000-000000000001';++function makeProvider(): TFYSandboxProvider {+ return new TFYSandboxProvider({+ serverUrl: SERVER_URL,+ natsBridgeUrl: 'ws://nats.example',+ tenantName: 'acme',+ fileMaxBytesForDownload: 1024,+ logger: makeSilentLogger(),+ });+}++function mockFetch({ status, body }: { status: number; body: unknown }): jest.SpiedFunction<typeof globalThis.fetch> {+ return jest+ .spyOn(globalThis, 'fetch')+ .mockResolvedValue(new Response(JSON.stringify(body), { status, headers: { 'Content-Type': 'application/json' } }));+}++afterEach(() => {+ jest.restoreAllMocks();+});++describe('TFYSandboxProvider.uploadFile', () => {+ it('POSTs the raw bytes to /files/upload', async () => {+ const timeout = jest.spyOn(AbortSignal, 'timeout');+ const fetchMock = mockFetch({ status: 200, body: { success: true } });+ const content = Buffer.from([0x00, 0xff, 0x0a]);++ await makeProvider().uploadFile({+ sandboxId: SANDBOX_ID,+ remotePath: 'uploads/report.docx',+ content,+ });++ expect(timeout).toHaveBeenCalledWith(30 * 60 * 1000);+ expect(fetchMock).toHaveBeenCalledTimes(1);+ const [url, init] = fetchMock.mock.calls[0] ?? [];+ expect(String(url)).toBe(`${SERVER_URL}/files/upload?sandbox_id=${SANDBOX_ID}&path=uploads%2Freport.docx`);+ expect(init?.method).toBe('POST');+ expect(init?.headers).toEqual({ 'Content-Type': 'application/octet-stream' });+ expect(init?.body).toEqual(content);+ expect(init?.signal).toBe(timeout.mock.results[0]?.value);+ });++ it('throws the server error body when success is false', async () => {+ mockFetch({ status: 200, body: { success: false, error: 'File exceeds 26214400 bytes' } });++ await expect(+ makeProvider().uploadFile({+ sandboxId: SANDBOX_ID,+ remotePath: 'uploads/big.bin',+ content: Buffer.from('ok'),+ }),+ ).rejects.toThrow('File upload to sandbox failed: File exceeds 26214400 bytes');+ });++ it('rejects a sandbox that is not owned by the tenant', async () => {+ const fetchMock = mockFetch({ status: 200, body: { success: true } });++ await expect(+ makeProvider().uploadFile({+ sandboxId: 'other.00000000-0000-0000-0000-000000000001',+ remotePath: 'uploads/a.txt',+ content: Buffer.from('x'),+ }),+ ).rejects.toMatchObject({ name: 'SandboxTenantMismatchError' });+ expect(fetchMock).not.toHaveBeenCalled();+ });+});