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
| Method | Description | Returns |
|---|---|---|
create() | Create a workspace | Workspace |
list() | List workspaces | WorkspacesListResponse |
get() | Read one workspace | Workspace |
update() | Change its name, metadata, or network rules | Workspace |
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",
});| Field | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | no | none | Display name, 1 to 80 characters |
userId | string | no | "" | The end user this workspace belongs to; cannot change later |
metadata | Record<string, unknown> | no | {} | Your own labels |
networkPolicy | WorkspaceNetworkPolicy | no | { 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" });| Option | Type | Required | Default | Description |
|---|---|---|---|---|
userId | string | no | none | Only this end user's workspaces; "" for tenant-level ones |
limit | number | no | 50 | 1 to 200 per page |
cursor | string | no | none | nextCursor 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" },
});| Field | Type | Required | Description |
|---|---|---|---|
workspaceId | string | yes | Workspace ID (ws_…) |
name | string | null | no | New name; null removes it |
metadata | Record<string, unknown> | no | Replaces all metadata |
networkPolicy | WorkspaceNetworkPolicy | no | Replaces 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:
workspace_in_use: agents still use it.details.agentIdslists them.workspace_busy: the workspace is running a command. Try again shortly.workspace_not_found: no such workspace in your tenant.service_unavailable: try again with backoff.
Response types
Workspace
| Field | Type | Description |
|---|---|---|
id | string | Workspace ID (ws_…) |
tenantId | string | Your tenant ID |
name | string | null | Display name, or null |
userId | string | The end user it belongs to, or "" |
metadata | Record<string, unknown> | Your labels |
networkPolicy | WorkspaceNetworkPolicy | Outbound network rules |
createdAt | string | ISO 8601 timestamp |
updatedAt | string | ISO 8601 timestamp |
WorkspacesListResponse
interface WorkspacesListResponse {
data: Workspace[];
nextCursor: string | null;
}Pass nextCursor to the next list() call until it is null.