TypeScript SDK

Workspaces

Create, list, update, and delete workspaces with the TypeScript SDK.

client.workspaces manages the private file systems your agents work in. Every agent already gets a workspace when you create it, so use these methods when you want to share one workspace between agents, set its network rules, or clean it up. To learn how workspaces behave, read Workspaces.

const workspace = await client.workspaces.create({
  name: "Release files",
  networkPolicy: { mode: "allowlist", allowedHosts: ["registry.npmjs.org"] },
});

await client.agents.update({ agentId, workspaceId: workspace.id });

Every method takes one input object and accepts an optional abortSignal. Reading or changing a workspace record does not touch its files.

Available operations

MethodDescriptionReturns
create()Create a workspaceWorkspace
list()List workspacesWorkspacesListResponse
get()Read one workspaceWorkspace
update()Change its name, metadata, or network rulesWorkspace
delete()Delete a workspace and its files"completed" | "pending"

Methods

create()

Creates an empty workspace.

Signature: create(input?: CreateWorkspaceBody & ResourceRequestOptions): Promise<Workspace>

const workspace = await client.workspaces.create({
  name: "Release files",
  userId: "user_42",
});
FieldTypeRequiredDefaultDescription
namestringnononeDisplay name, 1 to 80 characters
userIdstringno""The end user this workspace belongs to; cannot change later
metadataRecord<string, unknown>no{}Your own labels
networkPolicyWorkspaceNetworkPolicyno{ mode: "unrestricted" }Outbound network rules

WorkspaceNetworkPolicy is one of:

  • { mode: "unrestricted" }: commands can reach any host.
  • { mode: "allowlist", allowedHosts: string[] }: only the listed hosts, at least one.
  • { mode: "offline" }: no outbound network.

The policy applies to every agent that uses the workspace. Returns Workspace. Errors: validation_failed.

list()

Lists workspaces, newest first.

Signature: list(input?: WorkspacesListOptions): Promise<WorkspacesListResponse>

const { data, nextCursor } = await client.workspaces.list({ userId: "user_42" });
OptionTypeRequiredDefaultDescription
userIdstringnononeOnly this end user's workspaces; "" for tenant-level ones
limitnumberno501 to 200 per page
cursorstringnononenextCursor from the previous page

Returns WorkspacesListResponse. Errors: validation_failed, invalid_cursor.

get()

Reads one workspace.

Signature: get(input: { workspaceId: string } & ResourceRequestOptions): Promise<Workspace>

const workspace = await client.workspaces.get({ workspaceId });

Returns Workspace. Errors: validation_failed, workspace_not_found.

update()

Changes a workspace's name, metadata, or network rules.

Signature: update(input: UpdateWorkspaceBody & { workspaceId: string } & ResourceRequestOptions): Promise<Workspace>

const workspace = await client.workspaces.update({
  workspaceId,
  networkPolicy: { mode: "offline" },
});
FieldTypeRequiredDescription
workspaceIdstringyesWorkspace ID (ws_…)
namestring | nullnoNew name; null removes it
metadataRecord<string, unknown>noReplaces all metadata
networkPolicyWorkspaceNetworkPolicynoReplaces the network rules

Pass at least one field. Fields you leave out stay as they are, and userId cannot change. Returns Workspace. Errors: validation_failed, workspace_not_found.

delete()

Deletes a workspace and all its files.

Signature: delete(input: { workspaceId: string } & ResourceRequestOptions): Promise<"completed" | "pending">

const status = await client.workspaces.delete({ workspaceId });

Move every agent that uses the workspace to another one first. Returns "completed" when the workspace is fully deleted, or "pending" when the rest of the cleanup finishes in the background.

Errors:

Response types

Workspace

FieldTypeDescription
idstringWorkspace ID (ws_…)
tenantIdstringYour tenant ID
namestring | nullDisplay name, or null
userIdstringThe end user it belongs to, or ""
metadataRecord<string, unknown>Your labels
networkPolicyWorkspaceNetworkPolicyOutbound network rules
createdAtstringISO 8601 timestamp
updatedAtstringISO 8601 timestamp

WorkspacesListResponse

interface WorkspacesListResponse {
  data: Workspace[];
  nextCursor: string | null;
}

Pass nextCursor to the next list() call until it is null.

Next

On this page