Skip to main content

work_items

Creates, updates, deletes, gets or lists a work_items resource.

Overview

Namework_items
TypeResource
Idanthropic.environments.work_items

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
idstringWork identifier (e.g., 'work_...')
environment_idstringEnvironment identifier this work belongs to (e.g., `env_...`)
acknowledged_atstringRFC 3339 timestamp when the work item was acknowledged and assigned to a self-hosted sandbox
created_atstringRFC 3339 timestamp when work was created
dataobjectThe actual work to be performed
latest_heartbeat_atstringRFC 3339 timestamp of the most recent heartbeat
metadataobjectUser-provided metadata key-value pairs associated with this work item
started_atstringRFC 3339 timestamp when work execution started
statestringCurrent state of the work item (queued, starting, active, stopping, stopped)
stop_requested_atstringRFC 3339 timestamp when stop was requested
stopped_atstringRFC 3339 timestamp when work execution stopped
typestringThe type of object (always 'work') (work)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
getselectenvironment_id, work_idNote: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Retrieve detailed information about a specific work item.
listselectenvironment_idNote: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

List work items in an environment.
updateupdateenvironment_id, work_id, metadataNote: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Update work item metadata with merge semantics.
pollexecenvironment_idblock_ms, reclaim_older_than_msNote: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Long poll for work items in the queue.
ackexecenvironment_id, work_idNote: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Acknowledge receipt of a work item, transitioning it from 'queued' to 'starting' and removing it from the queue.
heartbeatexecenvironment_id, work_iddesired_ttl_seconds, expected_last_heartbeatNote: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Record a heartbeat for a work item to maintain the lease.
stopexecenvironment_id, work_idNote: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Stop a work item, initiating graceful or forced shutdown.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
environment_idstring (example: env_011CZkZ9X2dpNyB7HsEFoRfW)
work_idstring
block_msintegerHow long to wait for work to arrive before returning. Must be 1-999 in milliseconds. Defaults to non-blocking (returns immediately if no work is available).
desired_ttl_secondsintegerDesired TTL in seconds
expected_last_heartbeatstringExpected last_heartbeat for conditional update (optimistic concurrency). Use literal 'NO_HEARTBEAT' to claim an unclaimed lease (first heartbeat). For subsequent heartbeats, echo the server's previous last_heartbeat value exactly. Returns 412 Precondition Failed if the actual value doesn't match.
reclaim_older_than_msintegerReclaim unacknowledged work items older than this many milliseconds. If omitted, uses the default (5000ms).

SELECT examples

Note: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Retrieve detailed information about a specific work item.

SELECT
id,
environment_id,
acknowledged_at,
created_at,
data,
latest_heartbeat_at,
metadata,
started_at,
state,
stop_requested_at,
stopped_at,
type
FROM anthropic.environments.work_items
WHERE environment_id = '{{ environment_id }}' -- required
AND work_id = '{{ work_id }}' -- required
;

UPDATE examples

Note: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Update work item metadata with merge semantics.

UPDATE anthropic.environments.work_items
SET
metadata = '{{ metadata }}'
WHERE
environment_id = '{{ environment_id }}' --required
WHERE work_id = '{{ work_id }}' --required
AND metadata = '{{ metadata }}' --required
RETURNING
id,
environment_id,
acknowledged_at,
created_at,
data,
latest_heartbeat_at,
metadata,
started_at,
state,
stop_requested_at,
stopped_at,
type;

Lifecycle Methods

Note: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.

Long poll for work items in the queue.

EXEC anthropic.environments.work_items.poll
@environment_id='{{ environment_id }}' --required,
@block_ms='{{ block_ms }}',
@reclaim_older_than_ms='{{ reclaim_older_than_ms }}'
;