An open-source, faster Devin alternative
TypeScript
Show organization VM package profiles in settings (#765)
Mohamed Habibdebb8110d94e
diff --git a/cloudflare-workers/api-edge/src/managed_agents.test.ts b/cloudflare-workers/api-edge/src/managed_agents.test.tsindex 68fe14be..167c344a 100644--- a/cloudflare-workers/api-edge/src/managed_agents.test.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.test.ts@@ -54,6 +54,60 @@ describe("managed agents proxy", () => {expect(Number(payload.exp) - Number(payload.iat)).toBe(120);});+ it("exposes only the safe organization runtime profile label", async () => {+ const fetchMock = vi.fn().mockResolvedValue(+ Response.json({+ customized: true,+ displayName: "Cypen pentesting",+ profileId: "cypen-jxscout",+ imageArn: "private-image-identifier",+ imageVersion: "9.0",+ }),+ );+ vi.stubGlobal("fetch", fetchMock);++ const response = await proxyManagedAgents(+ new Request(+ "https://mo-oc-dev.com/api/dashboard/managed-agents/account/runtime-profile",+ ),+ {+ MANAGED_AGENTS_API_URL: "https://managedagents.test",+ OC_MANAGED_AGENTS_SECRET: "test-secret",+ },+ { orgID: "org_test", userID: "user_test", role: "admin" },+ "/api/dashboard/managed-agents",+ );++ expect(response.status).toBe(200);+ await expect(response.json()).resolves.toEqual({+ customized: true,+ displayName: "Cypen pentesting",+ });+ expect(fetchMock.mock.calls[0]?.[0].toString()).toBe(+ "https://managedagents.test/v1/account/runtime-profile",+ );+ });++ it("keeps runtime profile assignment operator-only", async () => {+ const fetchMock = vi.fn();+ vi.stubGlobal("fetch", fetchMock);+ const response = await proxyManagedAgents(+ new Request(+ "https://mo-oc-dev.com/api/dashboard/managed-agents/account/runtime-profile",+ { method: "POST", body: JSON.stringify({ profileId: "other" }) },+ ),+ {+ MANAGED_AGENTS_API_URL: "https://managedagents.test",+ OC_MANAGED_AGENTS_SECRET: "test-secret",+ },+ { orgID: "org_test", userID: "user_test", role: "admin" },+ "/api/dashboard/managed-agents",+ );++ expect(response.status).toBe(404);+ expect(fetchMock).not.toHaveBeenCalled();+ });+it("forwards managed GitHub project connection requests", async () => {const fetchMock = vi.fn().mockResolvedValue(Response.json({@@ -407,7 +461,9 @@ describe("managed agents proxy", () => {kind: "claude_subscription",status: "connected",});- expect(JSON.stringify(body)).not.toMatch(/credentialCiphertext|setup-token/);+ expect(JSON.stringify(body)).not.toMatch(+ /credentialCiphertext|setup-token/,+ );});it("accepts an OpenAI-compatible connection and strips custody fields", async () => {@@ -433,15 +489,18 @@ describe("managed agents proxy", () => {}),);const response = await proxyManagedAgents(- new Request("https://mo-oc-dev.com/api/managed-agents/model-access/connections", {- method: "POST",- headers: { "content-type": "application/json" },- body: JSON.stringify({- provider: "openai_compatible",- api_key: "write-only-key",- base_url: "https://api.scx.ai/v1",- }),- }),+ new Request(+ "https://mo-oc-dev.com/api/managed-agents/model-access/connections",+ {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({+ provider: "openai_compatible",+ api_key: "write-only-key",+ base_url: "https://api.scx.ai/v1",+ }),+ },+ ),{OC_MANAGED_AGENTS_SECRET: "test-secret",MANAGED_AGENTS_API_URL: "https://managedagents.test",@@ -458,7 +517,9 @@ describe("managed agents proxy", () => {kind: "openai_compatible_api",baseUrl: "https://api.scx.ai/v1",});- expect(JSON.stringify(body)).not.toMatch(/write-only-key|credentialCiphertext|must-not-leak/);+ expect(JSON.stringify(body)).not.toMatch(+ /write-only-key|credentialCiphertext|must-not-leak/,+ );});it("proxies project model routes without exposing private audit metadata", async () => {@@ -479,15 +540,18 @@ describe("managed agents proxy", () => {),);const response = await proxyManagedAgents(- new Request("https://mo-oc-dev.com/api/managed-agents/projects/prj_test/model-routes/development", {- method: "PUT",- headers: { "content-type": "application/json" },- body: JSON.stringify({- connection_id: "mac_scx",- model: "GLM-5.3",- fallback: "fail",- }),- }),+ new Request(+ "https://mo-oc-dev.com/api/managed-agents/projects/prj_test/model-routes/development",+ {+ method: "PUT",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({+ connection_id: "mac_scx",+ model: "GLM-5.3",+ fallback: "fail",+ }),+ },+ ),{OC_MANAGED_AGENTS_SECRET: "test-secret",MANAGED_AGENTS_API_URL: "https://managedagents.test",@@ -509,19 +573,24 @@ describe("managed agents proxy", () => {});it("removes a project model route without deleting its connection", async () => {- const fetchSpy = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {- expect(init?.method).toBe("DELETE");- expect(await new Response(init?.body).text()).toBe("{}");- return new Response(null, { status: 204 });- });+ const fetchSpy = vi.fn(+ async (_input: RequestInfo | URL, init?: RequestInit) => {+ expect(init?.method).toBe("DELETE");+ expect(await new Response(init?.body).text()).toBe("{}");+ return new Response(null, { status: 204 });+ },+ );vi.stubGlobal("fetch", fetchSpy);const response = await proxyManagedAgents(- new Request("https://mo-oc-dev.com/api/managed-agents/projects/prj_test/model-routes/development", {- method: "DELETE",- headers: { "content-type": "application/json" },- body: "{}",- }),+ new Request(+ "https://mo-oc-dev.com/api/managed-agents/projects/prj_test/model-routes/development",+ {+ method: "DELETE",+ headers: { "content-type": "application/json" },+ body: "{}",+ },+ ),{OC_MANAGED_AGENTS_SECRET: "test-secret",MANAGED_AGENTS_API_URL: "https://managedagents.test",@@ -701,20 +770,23 @@ describe("managed agents proxy", () => {expect(headers.get("x-forwarded-for")).toBeNull();expect(headers.get("x-request-id")).not.toBe("spoofed");expect(await new Response(init?.body).json()).toEqual(sentryBody);- return Response.json({- request: {- id: "whr_request",- webhookId: "wh_0123456789abcdef0123456789abcdef",- projectId: "prj_test",- environment: "development",- agentId: "oncall",- sessionId: "session_pending",- outcome: "pending",- attempt: 0,- createdAt: "2026-09-08T00:00:00.000Z",- updatedAt: "2026-09-08T00:00:00.000Z",+ return Response.json(+ {+ request: {+ id: "whr_request",+ webhookId: "wh_0123456789abcdef0123456789abcdef",+ projectId: "prj_test",+ environment: "development",+ agentId: "oncall",+ sessionId: "session_pending",+ outcome: "pending",+ attempt: 0,+ createdAt: "2026-09-08T00:00:00.000Z",+ updatedAt: "2026-09-08T00:00:00.000Z",+ },},- }, { status: 202 });+ { status: 202 },+ );},);vi.stubGlobal("fetch", fetchSpy);@@ -755,7 +827,11 @@ describe("managed agents proxy", () => {const response = await handleAgentWebhookInvocation(new Request("https://app.opencomputer.dev/api/agent-webhooks/wh_0123456789abcdef0123456789abcdef/bad%20token",- { method: "POST", headers: { "content-type": "application/json" }, body: "{}" },+ {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: "{}",+ },),{},);@@ -987,28 +1063,33 @@ describe("managed agents proxy", () => {});it("proxies bounded project database queries without exposing backend fields", async () => {- const fetchSpy = vi.fn(async (_input: RequestInfo | URL) => Response.json({- environment: "development",- result: {- columns: ["id", "token"],- rows: [{ id: 1, token: "application-owned-value", private: "drop" }],- rowsAffected: 0,- truncated: false,- provider: "private",- },- }));+ const fetchSpy = vi.fn(async (_input: RequestInfo | URL) =>+ Response.json({+ environment: "development",+ result: {+ columns: ["id", "token"],+ rows: [{ id: 1, token: "application-owned-value", private: "drop" }],+ rowsAffected: 0,+ truncated: false,+ provider: "private",+ },+ }),+ );vi.stubGlobal("fetch", fetchSpy);const response = await proxyManagedAgents(- new Request("https://app.opencomputer.dev/api/managed-agents/projects/prj_test/database/query", {- method: "POST",- headers: { "content-type": "application/json" },- body: JSON.stringify({- environment: "development",- sql: "SELECT id, token FROM records",- parameters: [],- }),- }),+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/projects/prj_test/database/query",+ {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({+ environment: "development",+ sql: "SELECT id, token FROM records",+ parameters: [],+ }),+ },+ ),{OC_MANAGED_AGENTS_SECRET: "test-secret",MANAGED_AGENTS_API_URL: "https://managedagents.test",@@ -1949,7 +2030,9 @@ describe("managed agents proxy", () => {});it("answers 404 for setup routes outside the contract without contacting the backend", async () => {- const fetchSpy = vi.fn(async () => Response.json({ setup: backendSetup }));+ const fetchSpy = vi.fn(async () =>+ Response.json({ setup: backendSetup }),+ );vi.stubGlobal("fetch", fetchSpy);for (const [method, path] of [@@ -1961,9 +2044,12 @@ describe("managed agents proxy", () => {["GET", "/channels/slack/setups/setup_1/cancel/extra"],]) {const response = await proxyManagedAgents(- new Request(`https://app.opencomputer.dev/api/managed-agents${path}`, {- method,- }),+ new Request(+ `https://app.opencomputer.dev/api/managed-agents${path}`,+ {+ method,+ },+ ),env,caller,"/api/managed-agents",@@ -2164,7 +2250,10 @@ describe("managed agents proxy", () => {{method: "POST",headers: { "content-type": "application/json" },- body: JSON.stringify({ agentId: "coder@development", name: "Patch" }),+ body: JSON.stringify({+ agentId: "coder@development",+ name: "Patch",+ }),},),env,@@ -3030,7 +3119,11 @@ describe("managed agents proxy", () => {activity: {activeTurnId: null,queued: 0,- lastSettledTurn: { id: "turn-1", status: "completed", at: "2026-09-15T00:01:00.000Z" },+ lastSettledTurn: {+ id: "turn-1",+ status: "completed",+ at: "2026-09-15T00:01:00.000Z",+ },},result: null,accountId: "org_test",@@ -3080,12 +3173,18 @@ describe("managed agents proxy", () => {activity: {activeTurnId: null,queued: 0,- lastSettledTurn: { id: "turn-1", status: "completed", at: "2026-09-15T00:01:00.000Z" },+ lastSettledTurn: {+ id: "turn-1",+ status: "completed",+ at: "2026-09-15T00:01:00.000Z",+ },},result: null,},]);- expect(JSON.stringify(body)).not.toMatch(/accountId|runtimeId|org_test|internal-runtime/);+ expect(JSON.stringify(body)).not.toMatch(+ /accountId|runtimeId|org_test|internal-runtime/,+ );});it("patches session labels and returns the sanitized session with its labels", async () => {@@ -3123,7 +3222,10 @@ describe("managed agents proxy", () => {);expect(response.status).toBe(200);- const [target, init] = fetchSpy.mock.calls[0] as unknown as [URL, RequestInit];+ const [target, init] = fetchSpy.mock.calls[0] as unknown as [+ URL,+ RequestInit,+ ];expect(String(target)).toBe("https://managedagents.test/v1/sessions/session-1/labels",);@@ -3160,13 +3262,21 @@ describe("managed agents proxy", () => {"fetch",vi.fn(async () =>Response.json(- { error: { code, message: "Label key \"Bad\" must match /internal-pattern/" } },+ {+ error: {+ code,+ message: 'Label key "Bad" must match /internal-pattern/',+ },+ },{ status: 400 },),),);const response = await proxyManagedAgents(- new Request(`https://app.opencomputer.dev/api/managed-agents${path}`, init),+ new Request(+ `https://app.opencomputer.dev/api/managed-agents${path}`,+ init,+ ),{ OC_MANAGED_AGENTS_SECRET: "test-secret" },{ orgID: "org_test", userID: "user_test" },"/api/managed-agents",@@ -3228,7 +3338,8 @@ describe("managed agents proxy", () => {{error: {code: "idempotency_conflict",- message: "idempotencyKey was already used with different input, payload, or mode",+ message:+ "idempotencyKey was already used with different input, payload, or mode",},},{ status: 409 },@@ -3260,7 +3371,12 @@ describe("managed agents proxy", () => {"fetch",vi.fn(async () =>Response.json(- { error: { code: "invalid_payload", message: "payload cannot exceed 32 KB of JSON" } },+ {+ error: {+ code: "invalid_payload",+ message: "payload cannot exceed 32 KB of JSON",+ },+ },{ status: 400 },),),@@ -3426,14 +3542,18 @@ describe("managed agents proxy", () => {"/api/managed-agents",);const detail = await proxyManagedAgents(- new Request("https://app.opencomputer.dev/api/managed-agents/sessions/session-1"),+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/sessions/session-1",+ ),env,caller,"/api/managed-agents",);expect(list.status).toBe(200);expect(detail.status).toBe(200);- const listBody = (await list.json()) as { sessions: Array<Record<string, unknown>> };+ const listBody = (await list.json()) as {+ sessions: Array<Record<string, unknown>>;+ };const detailBody = (await detail.json()) as Record<string, unknown>;// Application data is opaque: the same value from both routes.@@ -3444,7 +3564,9 @@ describe("managed agents proxy", () => {// replay; it is not part of the documented session.expect(detailBody).not.toHaveProperty("creation");expect(detailBody.labels).toEqual({ user_id: "u-42", topic: "t" });- expect((detailBody.turns as Array<Record<string, unknown>>)[0].payload).toEqual({+ expect(+ (detailBody.turns as Array<Record<string, unknown>>)[0].payload,+ ).toEqual({userId: "u-42",repo: "acme/web",});@@ -3480,7 +3602,11 @@ describe("managed agents proxy", () => {tool: "report",callId: "call-1",title: "report",- output: { userId: "u-42", pr: { runtimeId: "r-9" }, artifact: "build-12" },+ output: {+ userId: "u-42",+ pr: { runtimeId: "r-9" },+ artifact: "build-12",+ },result: true,runtimeId: "internal-runtime",},@@ -3509,7 +3635,11 @@ describe("managed agents proxy", () => {tool: "report",callId: "call-1",title: "report",- output: { userId: "u-42", pr: { runtimeId: "r-9" }, artifact: "build-12" },+ output: {+ userId: "u-42",+ pr: { runtimeId: "r-9" },+ artifact: "build-12",+ },result: true,},}),@@ -3620,24 +3750,32 @@ describe("managed agents proxy", () => {);expect(init.method).toBe("POST");expect(await new Response(init.body).json()).toEqual(body);- expect(await response.json()).toEqual({ subscription: publicSubscription });+ expect(await response.json()).toEqual({+ subscription: publicSubscription,+ });});it("lists, reads and deletes subscriptions", async () => {- const fetchSpy = vi.fn(async (input: URL | string, init?: RequestInit) => {- const url = String(input);- if (init?.method === "DELETE") return new Response(null, { status: 204 });- if (url.endsWith("/event-subscriptions")) {- return Response.json({ subscriptions: [subscription] });- }- return Response.json({ subscription });- });+ const fetchSpy = vi.fn(+ async (input: URL | string, init?: RequestInit) => {+ const url = String(input);+ if (init?.method === "DELETE")+ return new Response(null, { status: 204 });+ if (url.endsWith("/event-subscriptions")) {+ return Response.json({ subscriptions: [subscription] });+ }+ return Response.json({ subscription });+ },+ );vi.stubGlobal("fetch", fetchSpy);const call = (path: string, method = "GET") =>proxyManagedAgents(- new Request(`https://app.opencomputer.dev/api/managed-agents${path}`, {- method,- }),+ new Request(+ `https://app.opencomputer.dev/api/managed-agents${path}`,+ {+ method,+ },+ ),env,caller,"/api/managed-agents",@@ -3693,9 +3831,9 @@ describe("managed agents proxy", () => {"/api/managed-agents",);expect(response.status).toBe(409);- expect(((await response.json()) as { error: { code: string } }).error.code).toBe(- "destination_session_ended",- );+ expect(+ ((await response.json()) as { error: { code: string } }).error.code,+ ).toBe("destination_session_ended");});it("does not admit other methods on subscription routes", async () => {@@ -3707,9 +3845,12 @@ describe("managed agents proxy", () => {["/projects/prj_1/event-subscriptions/evs_1", "POST"],] as const) {const response = await proxyManagedAgents(- new Request(`https://app.opencomputer.dev/api/managed-agents${path}`, {- method,- }),+ new Request(+ `https://app.opencomputer.dev/api/managed-agents${path}`,+ {+ method,+ },+ ),env,caller,"/api/managed-agents",@@ -3741,7 +3882,10 @@ describe("managed agents proxy", () => {subscriptionId: "evs_1",eventId: "event_9",eventType: "turn.completed",- destination: { type: "session", sessionId: "ses_coordinator" },+ destination: {+ type: "session",+ sessionId: "ses_coordinator",+ },status: "delivered",attempt: 1,receipt: { sessionId: "ses_coordinator", turnId: "turn-7" },@@ -4018,33 +4162,35 @@ describe("managed agents proxy", () => {});it("forwards memory conditional headers and returns the documented status codes", async () => {- const fetchSpy = vi.fn(async (_target: RequestInfo | URL, init?: RequestInit) => {- const method = init?.method ?? "GET";- const headers = new Headers(init?.headers);- if (method === "PUT" && headers.get("if-none-match") === "*") {- expect(headers.get("if-match")).toBeNull();- expect(await new Response(init?.body).json()).toEqual({- title: "Workshop requirements",- text: "Exercises must run on Node.js 22.",- });- return Response.json(workshopDocument, {- status: 201,- headers: { etag: '"rev-7"' },- });- }- if (method === "PATCH") {- expect(headers.get("if-match")).toBe('"rev-7"');- return Response.json(- { ...workshopDocument, agentWrites: "disabled", revision: "rev-8" },- { headers: { etag: '"rev-8"' } },- );- }- if (method === "DELETE") {- expect(headers.get("if-match")).toBe('"rev-8"');- return new Response(null, { status: 204 });- }- throw new Error(`unexpected ${method}`);- });+ const fetchSpy = vi.fn(+ async (_target: RequestInfo | URL, init?: RequestInit) => {+ const method = init?.method ?? "GET";+ const headers = new Headers(init?.headers);+ if (method === "PUT" && headers.get("if-none-match") === "*") {+ expect(headers.get("if-match")).toBeNull();+ expect(await new Response(init?.body).json()).toEqual({+ title: "Workshop requirements",+ text: "Exercises must run on Node.js 22.",+ });+ return Response.json(workshopDocument, {+ status: 201,+ headers: { etag: '"rev-7"' },+ });+ }+ if (method === "PATCH") {+ expect(headers.get("if-match")).toBe('"rev-7"');+ return Response.json(+ { ...workshopDocument, agentWrites: "disabled", revision: "rev-8" },+ { headers: { etag: '"rev-8"' } },+ );+ }+ if (method === "DELETE") {+ expect(headers.get("if-match")).toBe('"rev-8"');+ return new Response(null, { status: 204 });+ }+ throw new Error(`unexpected ${method}`);+ },+ );vi.stubGlobal("fetch", fetchSpy);const path ="https://app.opencomputer.dev/api/managed-agents/projects/prj_1/memory/requirements/documents/workshop?environment=development";@@ -4120,7 +4266,10 @@ describe("managed agents proxy", () => {"https://app.opencomputer.dev/api/managed-agents/projects/prj_1/memory/requirements/documents/workshop?environment=development",{method: "PUT",- headers: { "content-type": "application/json", "if-match": '"rev-6"' },+ headers: {+ "content-type": "application/json",+ "if-match": '"rev-6"',+ },body: JSON.stringify({ text: "stale" }),},),@@ -4212,7 +4361,9 @@ describe("managed agents proxy", () => {);const response = await proxyManagedAgents(- new Request("https://app.opencomputer.dev/api/managed-agents/sessions/ses_1"),+ new Request(+ "https://app.opencomputer.dev/api/managed-agents/sessions/ses_1",+ ),memoryEnv,memoryCaller,"/api/managed-agents",@@ -4420,7 +4571,9 @@ describe("managed agents proxy", () => {});// A model id that is not a model id is not echoed.expect(- publicFailure({ message: "Model unavailable: sk-ant-api03-0123456789abcdefghijklmnop/x" }),+ publicFailure({+ message: "Model unavailable: sk-ant-api03-0123456789abcdefghijklmnop/x",+ }),).toEqual({code: "model_unavailable",message: "The requested model is not available to this agent.",@@ -4465,25 +4618,36 @@ describe("managed agents proxy", () => {});// A call that bypassed the retry (compaction, titling) failed once: no// retry is claimed.- expect(publicFailure(providerFailure("internal", { status: 502 }))).toEqual({- code: "model_stream_failed",- message:- "The model call to anthropic/claude-sonnet-4.6 failed before it finished.",- model: "anthropic/claude-sonnet-4.6",- });+ expect(publicFailure(providerFailure("internal", { status: 502 }))).toEqual(+ {+ code: "model_stream_failed",+ message:+ "The model call to anthropic/claude-sonnet-4.6 failed before it finished.",+ model: "anthropic/claude-sonnet-4.6",+ },+ );expect(publicFailure({message: "socket hang up",- failure: { class: "provider", subtype: "invalid-output", retry: { attempts: 3, hostGranted: false } },+ failure: {+ class: "provider",+ subtype: "invalid-output",+ retry: { attempts: 3, hostGranted: false },+ },}),).toEqual({code: "model_stream_failed",- message: "The model call failed before it finished and its retry failed too.",+ message:+ "The model call failed before it finished and its retry failed too.",});// A model id with a variant suffix survives intact.expect(publicFailure(- providerFailure("unknown", { model: "meta-llama/llama-3.3-70b-instruct:free" }, 2),+ providerFailure(+ "unknown",+ { model: "meta-llama/llama-3.3-70b-instruct:free" },+ 2,+ ),),).toEqual({code: "model_stream_failed",@@ -4497,7 +4661,9 @@ describe("managed agents proxy", () => {message: "The model provider rejected the request.",});}- expect(publicFailure(providerFailure("invalid-request", { status: 400 }))).toEqual({+ expect(+ publicFailure(providerFailure("invalid-request", { status: 400 })),+ ).toEqual({code: "model_rejected",message: "The model provider rejected the request.",});@@ -4505,47 +4671,69 @@ describe("managed agents proxy", () => {expect(publicFailure({...providerFailure("invalid-request", { status: 400 }),- message: "prompt is too long: 214000 tokens > 200000 maximum context length",+ message:+ "prompt is too long: 214000 tokens > 200000 maximum context length",}),).toEqual({code: "context_too_long",message: "The conversation is too long for the model's context window.",});- expect(publicFailure(providerFailure("no-route", { model: "openai/gpt-5" }))).toEqual({+ expect(+ publicFailure(providerFailure("no-route", { model: "openai/gpt-5" })),+ ).toEqual({code: "model_unavailable",message: "The model openai/gpt-5 is not available to this agent.",model: "openai/gpt-5",});// A credential-shaped model id is dropped, never echoed.expect(- publicFailure(providerFailure("transport", { model: "sk-ant-api03-0123456789abcdefghijklmnop" }, 2)),+ publicFailure(+ providerFailure(+ "transport",+ { model: "sk-ant-api03-0123456789abcdefghijklmnop" },+ 2,+ ),+ ),).toEqual({code: "model_stream_failed",- message: "The model call failed before it finished and its retry failed too.",+ message:+ "The model call failed before it finished and its retry failed too.",});// Fields of another class fall through to the text rules.expect(publicFailure({message: "Sandbox operation timed out",- failure: { class: "tool", subtype: "execution", retry: { attempts: 1, hostGranted: false } },+ failure: {+ class: "tool",+ subtype: "execution",+ retry: { attempts: 1, hostGranted: false },+ },}),- ).toEqual({ code: "sandbox_timeout", message: "A sandbox command did not finish in time." });+ ).toEqual({+ code: "sandbox_timeout",+ message: "A sandbox command did not finish in time.",+ });expect(publicFailure({- message: "prompt is too long: 214000 tokens > 200000 maximum context length",+ message:+ "prompt is too long: 214000 tokens > 200000 maximum context length",}),).toEqual({code: "context_too_long",message: "The conversation is too long for the model's context window.",});expect(- publicFailure({ message: "Tool module exported an unregistered tool: lookup_venue" }),+ publicFailure({+ message: "Tool module exported an unregistered tool: lookup_venue",+ }),).toEqual({code: "tool_failed",message: "Tool lookup_venue failed.",tool: "lookup_venue",});- expect(publicFailure({ message: "The tool has no edge implementation" })).toEqual({+ expect(+ publicFailure({ message: "The tool has no edge implementation" }),+ ).toEqual({code: "tool_failed",message: "A tool failed.",});@@ -4555,22 +4743,31 @@ describe("managed agents proxy", () => {});expect(publicFailure({- message: "Sandbox acquisition returned 503: {\"error\":\"no capacity in us-east\"}",+ message:+ 'Sandbox acquisition returned 503: {"error":"no capacity in us-east"}',}),).toEqual({code: "sandbox_failed",message: "The sandbox could not run this turn.",});- expect(publicFailure({ reason: "Runtime harness is not ready\u0007" })).toEqual({+ expect(+ publicFailure({ reason: "Runtime harness is not ready\u0007" }),+ ).toEqual({code: "runtime_failed",message: "The agent runtime failed before the turn finished.",});- expect(publicFailure({ message: "The Workerd runtime stream ended before the turn did" })).toEqual({+ expect(+ publicFailure({+ message: "The Workerd runtime stream ended before the turn did",+ }),+ ).toEqual({code: "runtime_failed",message: "The agent runtime failed before the turn finished.",});expect(- publicFailure({ message: "The deployment is missing tool module \"tools/x.js\"" }),+ publicFailure({+ message: 'The deployment is missing tool module "tools/x.js"',+ }),).toEqual({code: "deployment_invalid",message: "The deployment could not be loaded by the runtime.",diff --git a/cloudflare-workers/api-edge/src/managed_agents.ts b/cloudflare-workers/api-edge/src/managed_agents.tsindex dc976b6e..43d7a899 100644--- a/cloudflare-workers/api-edge/src/managed_agents.ts+++ b/cloudflare-workers/api-edge/src/managed_agents.ts@@ -210,7 +210,10 @@ async function publicErrorResponse(upstream: Response): Promise<Response> {? "template_manifest_missing": backendCode;let message = "The agent request could not be completed.";- const slackSetupMessage = Object.hasOwn(SLACK_SETUP_ERROR_MESSAGES, backendCode)+ const slackSetupMessage = Object.hasOwn(+ SLACK_SETUP_ERROR_MESSAGES,+ backendCode,+ )? SLACK_SETUP_ERROR_MESSAGES[backendCode]: undefined;if (slackSetupMessage) {@@ -629,10 +632,16 @@ function publicChannel(value: unknown): Record<string, unknown> {};}-const SLACK_SETUP_ACTIONS = new Set(["create", "authorize", "manual", "cancel"]);+const SLACK_SETUP_ACTIONS = new Set([+ "create",+ "authorize",+ "manual",+ "cancel",+]);const SLACK_SETUPS_ROUTE = /^\/channels\/slack\/setups$/;const SLACK_SETUP_ROUTE = /^\/channels\/slack\/setups\/[^/]+$/;-const SLACK_SETUP_AUTHORIZE_ROUTE = /^\/channels\/slack\/setups\/[^/]+\/authorize$/;+const SLACK_SETUP_AUTHORIZE_ROUTE =+ /^\/channels\/slack\/setups\/[^/]+\/authorize$/;const SLACK_SETUP_CANCEL_ROUTE = /^\/channels\/slack\/setups\/[^/]+\/cancel$/;/**@@ -953,7 +962,11 @@ function publicSessionResult(value: unknown): unknown {* compares on an idempotent replay. Dropped by position, since the name* filter is for the fields it lists.*/-const PRIVATE_SESSION_FIELDS = new Set(["runtimeEpoch", "memoryObject", "creation"]);+const PRIVATE_SESSION_FIELDS = new Set([+ "runtimeEpoch",+ "memoryObject",+ "creation",+]);/*** One turn of the snapshot. `payload` is the caller's own JSON and passes@@ -967,7 +980,9 @@ function publicTurn(entry: unknown): unknown {Object.entries(turn).flatMap(([key, child]): Array<[string, unknown]> => {if (key === "payload") return [[key, child]];if (key === "deliveries") {- return [[key, Array.isArray(child) ? child.map(publicDelivery) : child]];+ return [+ [key, Array.isArray(child) ? child.map(publicDelivery) : child],+ ];}if (PRIVATE_EVENT_KEYS.has(key)) return [];return [[key, stripPrivateValues(child)]];@@ -993,9 +1008,17 @@ function publicSessionSnapshot(value: unknown): unknown {if (key === "labels") return [[key, ownerLabels(source)]];if (key === "result") return [[key, publicSessionResult(child)]];if (key === "turns") {- return [[key, Array.isArray(child) ? child.map(publicTurn) : stripPrivateValues(child)]];+ return [+ [+ key,+ Array.isArray(child)+ ? child.map(publicTurn)+ : stripPrivateValues(child),+ ],+ ];}- if (PRIVATE_EVENT_KEYS.has(key) || PRIVATE_SESSION_FIELDS.has(key)) return [];+ if (PRIVATE_EVENT_KEYS.has(key) || PRIVATE_SESSION_FIELDS.has(key))+ return [];return [[key, stripPrivateValues(child)]];}),);@@ -1237,8 +1260,7 @@ function structuredFailure(}if (code === "model_stream_failed") {const retry = record(failure.retry);- const retried =- typeof retry?.attempts === "number" && retry.attempts > 1;+ const retried = typeof retry?.attempts === "number" && retry.attempts > 1;return {code,message: `The model call${model ? ` to ${model}` : ""} failed before it finished${retried ? " and its retry failed too" : ""}.`,@@ -1407,6 +1429,15 @@ function publicSuccessBody(includeAdminMetadata = false,): unknown {const body = record(value) ?? {};+ if (method === "GET" && suffix === "/account/runtime-profile") {+ return {+ customized: body.customized === true,+ displayName:+ typeof body.displayName === "string" && body.displayName.trim()+ ? body.displayName+ : "OpenComputer default",+ };+ }if (method === "GET" && suffix === "/agents") {return {agents: Array.isArray(body.agents)@@ -1438,7 +1469,10 @@ function publicSuccessBody(if (method === "POST" && suffix === "/projects") {return publicProject(body);}- if (method === "POST" && /^\/projects\/[^/]+\/database\/query$/.test(suffix)) {+ if (+ method === "POST" &&+ /^\/projects\/[^/]+\/database\/query$/.test(suffix)+ ) {const result = record(body.result) ?? {};const columns = strings(result.columns);return {@@ -1451,19 +1485,27 @@ function publicSuccessBody(return Object.fromEntries(columns.map((column) => {const cell = row[column];- return [column, typeof cell === "string" || typeof cell === "number" ? cell : null];+ return [+ column,+ typeof cell === "string" || typeof cell === "number"+ ? cell+ : null,+ ];}),);}): [],- rowsAffected: typeof result.rowsAffected === "number" ? result.rowsAffected : 0,+ rowsAffected:+ typeof result.rowsAffected === "number" ? result.rowsAffected : 0,truncated: result.truncated === true,},};}if (/^\/github(?:\/connect)?$/.test(suffix) ||- /^\/projects\/[^/]+\/github(?:\/(?:connect|attach|repositories))?$/.test(suffix)+ /^\/projects\/[^/]+\/github(?:\/(?:connect|attach|repositories))?$/.test(+ suffix,+ )) {return stripPrivateValues(body);}@@ -1615,7 +1657,10 @@ function publicSuccessBody(data: Array.isArray(body.data) ? body.data.map(publicModelRoute) : [],};}- if (method === "PUT" && /^\/projects\/[^/]+\/model-routes\/[^/]+$/.test(suffix)) {+ if (+ method === "PUT" &&+ /^\/projects\/[^/]+\/model-routes\/[^/]+$/.test(suffix)+ ) {return publicModelRoute(body);}if (method === "POST" && suffix === "/deployments") {@@ -2012,6 +2057,7 @@ async function deploySourceAgent(}function isAllowedManagedAgentsRoute(method: string, suffix: string): boolean {+ if (method === "GET" && suffix === "/account/runtime-profile") return true;if (method === "POST" && suffix === "/template-inspections") return true;if (method === "POST" && suffix === "/template-installations") return true;if (method === "GET" && /^\/template-installations\/[^/]+$/.test(suffix)) {@@ -2031,7 +2077,10 @@ function isAllowedManagedAgentsRoute(method: string, suffix: string): boolean {if (method === "GET" && suffix === "/github") return true;if (method === "POST" && suffix === "/github/connect") return true;if (method === "GET" && /^\/projects\/[^/]+$/.test(suffix)) return true;- if (method === "POST" && /^\/projects\/[^/]+\/database\/query$/.test(suffix)) {+ if (+ method === "POST" &&+ /^\/projects\/[^/]+\/database\/query$/.test(suffix)+ ) {return true;}if (method === "GET" && /^\/projects\/[^/]+\/source-archive$/.test(suffix)) {@@ -2043,7 +2092,10 @@ function isAllowedManagedAgentsRoute(method: string, suffix: string): boolean {) {return true;}- if (method === "GET" && /^\/projects\/[^/]+\/github\/repositories$/.test(suffix)) {+ if (+ method === "GET" &&+ /^\/projects\/[^/]+\/github\/repositories$/.test(suffix)+ ) {return true;}if (@@ -2580,7 +2632,8 @@ export async function proxyManagedAgents({error: {code: "unsupported_provider",- message: "Supported providers are Codex, Claude, OpenRouter, and OpenAI-compatible APIs.",+ message:+ "Supported providers are Codex, Claude, OpenRouter, and OpenAI-compatible APIs.",},},{ status: 400 },@@ -2604,7 +2657,11 @@ export async function proxyManagedAgents(const modelRouteWrite =(method === "PUT" || method === "DELETE") &&/^\/projects\/[^/]+\/model-routes\/[^/]+$/.test(suffix);- if (modelAccessConnectionWrite || modelAccessBindingEnable || modelRouteWrite) {+ if (+ modelAccessConnectionWrite ||+ modelAccessBindingEnable ||+ modelRouteWrite+ ) {try {if (!(await hasBYOKPlanAccess(env, caller.orgID))) {return byokPlanRequired();diff --git a/docs/agents/tools.mdx b/docs/agents/tools.mdxindex 6ebcc8be..e38c2e99 100644--- a/docs/agents/tools.mdx+++ b/docs/agents/tools.mdx@@ -53,15 +53,15 @@ the result to the model.## Tool definition-| Field | Required | Purpose |-| --- | --- | --- |-| `name` | yes | ID the model calls; letters, numbers, underscores, and hyphens only |-| `description` | yes | Explains what the tool does and when to use it |-| `input` | no | JSON Schema for tool arguments |-| `output` | no | JSON Schema describing the result; required on the result tool |-| `result` | no | `true` marks this tool as the agent's [result tool](#the-session-result); one per agent, and it must have `run` |-| `run` | yes* | Synchronous or asynchronous implementation |-| `preview` / `apply` | no | Supply these *instead of* `run` to [wait for a person](#wait-for-a-person-before-writing) |+| Field | Required | Purpose |+| ------------------- | -------- | --------------------------------------------------------------------------------------------------------------- |+| `name` | yes | ID the model calls; letters, numbers, underscores, and hyphens only |+| `description` | yes | Explains what the tool does and when to use it |+| `input` | no | JSON Schema for tool arguments |+| `output` | no | JSON Schema describing the result; required on the result tool |+| `result` | no | `true` marks this tool as the agent's [result tool](#the-session-result); one per agent, and it must have `run` |+| `run` | yes\* | Synchronous or asynchronous implementation |+| `preview` / `apply` | no | Supply these _instead of_ `run` to [wait for a person](#wait-for-a-person-before-writing) |\* A tool has either `run`, or `preview` and `apply` — never both, and neverjust one of the pair.@@ -73,15 +73,15 @@ appropriate, and any important precondition.The `run` function receives:-| Value | Purpose |-| --- | --- |-| `input` | Arguments created for the tool call |-| `sessionId` | Current session ID |-| `messageId` | Message containing the tool call |-| `toolCallId` | ID of this invocation, unique within the session |-| `agentId` | Agent executing the call |-| `signal` | Optional cancellation signal for abortable work |-| `reportProgress(metadata)` | Emits JSON-compatible progress metadata |+| Value | Purpose |+| -------------------------- | ------------------------------------------------ |+| `input` | Arguments created for the tool call |+| `sessionId` | Current session ID |+| `messageId` | Message containing the tool call |+| `toolCallId` | ID of this invocation, unique within the session |+| `agentId` | Agent executing the call |+| `signal` | Optional cancellation signal for abortable work |+| `reportProgress(metadata)` | Emits JSON-compatible progress metadata |Use the cancellation signal with `fetch()` and report progress before slowsteps:@@ -92,7 +92,9 @@ export const importCatalog = defineTool({description: "Import the latest product catalog; use only when asked",async run({ signal, reportProgress }) {await reportProgress({ phase: "downloading" });- const response = await fetch("https://example.com/catalog.json", { signal });+ const response = await fetch("https://example.com/catalog.json", {+ signal,+ });await reportProgress({ phase: "processing" });return { imported: response.ok };},@@ -228,6 +230,32 @@ export default function Agent() {`useTool()` also accepts a tool ID such as `useTool("web-search")` when theruntime already provides that tool.+## Give an agent a sandbox shell++Select the built-in `sandbox_exec` tool when an agent needs to run commands,+inspect files, or use installed CLI packages:++```tsx+import { useTool } from "@opencomputer/agent";++export default function Agent() {+ useTool("sandbox_exec");++ return "Use the sandbox for shell commands and keep durable work in /workspace.";+}+```++The agent runtime starts without a VM. The first `sandbox_exec` call lazily+acquires an isolated computer for the session, and later calls in that session+reuse it. Files that must survive restarts belong in `/workspace`; temporary+paths such as `/tmp` do not provide that persistence guarantee.++If your organization has an Enterprise custom package image, `sandbox_exec`+uses that image automatically. The agent definition still selects the same+tool ID, and cannot choose or override the image itself. You can see the+package image assigned to your organization under **Settings → Customize VM+packages**.+## Call external APIs safelyFor authenticated HTTP APIs, declare a connection, store the key as andiff --git a/web/src/api/mock.ts b/web/src/api/mock.tsindex d044d12d..2631ad4c 100644--- a/web/src/api/mock.ts+++ b/web/src/api/mock.ts@@ -1212,7 +1212,7 @@ type Handler = () => unknown// missing resource) — used for an agent with no deployment-source link.const NOT_FOUND = Symbol('not_found')-let managedAgentItems: Array<{+const managedAgentItems: Array<{id: stringname: stringactiveAlias: string@@ -1259,11 +1259,12 @@ const ROUTES: Array<[RegExp, Handler]> = [() => ({ data: [], next_cursor: null }),],[/^\/managed-agents\/agents$/, () => ({ agents: managedAgentItems })],- [/^\/managed-agents\/projects$/, () => ({ projects: managedProjects })],[- /^\/managed-agents\/model-access\/connections$/,- () => ({ data: [] }),+ /^\/managed-agents\/account\/runtime-profile$/,+ () => ({ customized: false, displayName: 'OpenComputer default' }),],+ [/^\/managed-agents\/projects$/, () => ({ projects: managedProjects })],+ [/^\/managed-agents\/model-access\/connections$/, () => ({ data: [] })],[/^\/managed-agents\/projects\/[^/]+\/model-access\/bindings$/,() => ({ data: [] }),diff --git a/web/src/managed-agents/api.ts b/web/src/managed-agents/api.tsindex 170a6ce8..b4d65103 100644--- a/web/src/managed-agents/api.ts+++ b/web/src/managed-agents/api.ts@@ -102,6 +102,11 @@ const agentsResponseSchema = z.object({agents: z.array(agentSchema),})+const managedRuntimeProfileSchema = z.object({+ customized: z.boolean(),+ displayName: z.string(),+})+const projectSchema = z.object({id: z.string(),slug: z.string(),@@ -794,6 +799,7 @@ const projectOverviewSchema = z.object({})export type ManagedAgentSummary = z.infer<typeof agentSchema>+export type ManagedRuntimeProfile = z.infer<typeof managedRuntimeProfileSchema>export type ManagedProject = z.infer<typeof projectSchema>export type ManagedProjectOverview = z.infer<typeof projectOverviewSchema>export type ManagedAgentDeployment = z.infer<typeof deploymentSchema>@@ -849,6 +855,14 @@ export async function getManagedAgents() {).agents}+export async function getManagedRuntimeProfile() {+ return apiFetch(+ '/managed-agents/account/runtime-profile',+ undefined,+ managedRuntimeProfileSchema,+ )+}+export async function getManagedProjects() {return (await apiFetch(diff --git a/web/src/pages/Settings.tsx b/web/src/pages/Settings.tsxindex a118b785..f5847e83 100644--- a/web/src/pages/Settings.tsx+++ b/web/src/pages/Settings.tsx@@ -32,6 +32,16 @@ import { Field, Input, Label } from '@/components/form'import { StatusBadge } from '@/components/status-badge'import { ConfirmDialog } from '@/components/confirm-dialog'import { Switch } from '@/components/ui/switch'+import {+ Dialog,+ DialogClose,+ DialogContent,+ DialogDescription,+ DialogFooter,+ DialogHeader,+ DialogTitle,+} from '@/components/ui/dialog'+import { getManagedRuntimeProfile } from '@/managed-agents/api'function ReadOnlyField({ label, value }: { label: string; value: ReactNode }) {return (@@ -72,6 +82,15 @@ export default function Settings() {queryKey: ['org'],queryFn: getOrg,})+ const {+ data: runtimeProfile,+ isLoading: runtimeProfileLoading,+ isError: runtimeProfileError,+ } = useQuery({+ queryKey: ['managed-runtime-profile'],+ queryFn: getManagedRuntimeProfile,+ retry: false,+ })// Local edits override the fetched name; null = "not edited" (avoids an// effect to sync the field with the query).@@ -79,6 +98,7 @@ export default function Settings() {const [saved, markSaved] = useTransientFlag(2000)const [domainInput, setDomainInput] = useState('')const [confirmRemoveDomain, setConfirmRemoveDomain] = useState(false)+ const [showRuntimeProfileInfo, setShowRuntimeProfileInfo] = useState(false)const name = draftName ?? org?.name ?? ''const saveMutation = useMutation({@@ -160,6 +180,38 @@ export default function Settings() {</div></Panel>+ <Panel className="p-6 lg:col-span-2">+ <div className="flex flex-col justify-between gap-4 sm:flex-row sm:items-center">+ <div>+ <PanelTitle>Customize VM packages</PanelTitle>+ <PanelDescription className="mt-1">+ Select the tools available to agents when they start a VM.+ </PanelDescription>+ <div className="mt-4">+ <Label>Selected package image</Label>+ <p className="text-foreground mt-1 text-sm font-medium">+ {runtimeProfileLoading+ ? 'Loading…'+ : runtimeProfileError+ ? 'Unavailable'+ : (runtimeProfile?.displayName ?? 'OpenComputer default')}+ </p>+ {runtimeProfile?.customized ? (+ <p className="text-muted-foreground mt-1 text-xs">+ A dedicated image is assigned to this organization.+ </p>+ ) : null}+ </div>+ </div>+ <Button+ variant="outline"+ onClick={() => setShowRuntimeProfileInfo(true)}+ >+ Edit+ </Button>+ </div>+ </Panel>+{/* Organization */}<Panel className="p-6"><div className="mb-5">@@ -366,6 +418,36 @@ export default function Settings() {})}/>++ <Dialog+ open={showRuntimeProfileInfo}+ onOpenChange={setShowRuntimeProfileInfo}+ >+ <DialogContent>+ <DialogHeader>+ <DialogTitle>Custom VM packages</DialogTitle>+ <DialogDescription>+ Custom package images are an Enterprise feature. The OpenComputer+ team builds and validates a dedicated image, then assigns it to+ your organization. Book a call with the team to get it set up.+ </DialogDescription>+ </DialogHeader>+ <DialogFooter>+ <DialogClose asChild>+ <Button variant="outline">Got it</Button>+ </DialogClose>+ <Button asChild>+ <a+ href="https://cal.com/team/digger/opencomputer-founder-chat"+ target="_blank"+ rel="noreferrer"+ >+ Book a call+ </a>+ </Button>+ </DialogFooter>+ </DialogContent>+ </Dialog></div>)}