Class: Anthropic::Resources::Beta::Environments::Work

Inherits:
Object
  • Object
show all
Defined in:
lib/anthropic/resources/beta/environments/work.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ Work

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Work.

Parameters:



313
314
315
# File 'lib/anthropic/resources/beta/environments/work.rb', line 313

def initialize(client:)
  @client = client
end

Instance Method Details

#ack(work_id, environment_id:, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::Environments::BetaSelfHostedWork

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.

Acknowledge receipt of a work item, transitioning it from ‘queued’ to ‘starting’ and removing it from the queue.

Parameters:

  • work_id (String)

    Path param

  • environment_id (String)

    Path param

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/anthropic/resources/beta/environments/work.rb', line 143

def ack(work_id, params)
  parsed, options = Anthropic::Beta::Environments::WorkAckParams.dump_request(params)
  environment_id =
    parsed.delete(:environment_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["v1/environments/%1$s/work/%2$s/ack?beta=true", environment_id, work_id],
    headers: parsed.transform_keys(betas: "anthropic-beta"),
    model: Anthropic::Beta::Environments::BetaSelfHostedWork,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#heartbeat(work_id, environment_id:, desired_ttl_seconds: nil, expected_last_heartbeat: nil, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::Environments::BetaSelfHostedWorkHeartbeatResponse

Some parameter documentations has been truncated, see Models::Beta::Environments::WorkHeartbeatParams for more details.

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.

Record a heartbeat for a work item to maintain the lease.

Parameters:

  • work_id (String)

    Path param

  • environment_id (String)

    Path param

  • desired_ttl_seconds (Integer, nil)

    Query param: Desired TTL in seconds

  • expected_last_heartbeat (String, nil)

    Query param: Expected last_heartbeat for conditional update (optimistic concurre

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/anthropic/resources/beta/environments/work.rb', line 185

def heartbeat(work_id, params)
  query_params = [:desired_ttl_seconds, :expected_last_heartbeat]
  parsed, options = Anthropic::Beta::Environments::WorkHeartbeatParams.dump_request(params)
  query = Anthropic::Internal::Util.encode_query_params(parsed.slice(*query_params))
  environment_id =
    parsed.delete(:environment_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :post,
    path: ["v1/environments/%1$s/work/%2$s/heartbeat?beta=true", environment_id, work_id],
    query: query,
    headers: parsed.except(*query_params).transform_keys(betas: "anthropic-beta"),
    model: Anthropic::Beta::Environments::BetaSelfHostedWorkHeartbeatResponse,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#list(environment_id, limit: nil, page: nil, betas: nil, request_options: {}) ⇒ Anthropic::Internal::PageCursor<Anthropic::Models::Beta::Environments::BetaSelfHostedWork>

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.

List work items in an environment.

Parameters:

  • environment_id (String)

    Path param

  • limit (Integer)

    Query param: Maximum number of work items to return

  • page (String, nil)

    Query param: Opaque cursor from previous response for pagination

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/anthropic/resources/beta/environments/work.rb', line 107

def list(environment_id, params = {})
  query_params = [:limit, :page]
  parsed, options = Anthropic::Beta::Environments::WorkListParams.dump_request(params)
  query = Anthropic::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: ["v1/environments/%1$s/work?beta=true", environment_id],
    query: query,
    headers: parsed.except(*query_params).transform_keys(betas: "anthropic-beta"),
    page: Anthropic::Internal::PageCursor,
    model: Anthropic::Beta::Environments::BetaSelfHostedWork,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#poll(environment_id, block_ms: nil, reclaim_older_than_ms: nil, betas: nil, anthropic_worker_id: nil, request_options: {}) ⇒ Anthropic::Models::Beta::Environments::BetaSelfHostedWork?

Some parameter documentations has been truncated, see Models::Beta::Environments::WorkPollParams for more details.

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.

Parameters:

  • environment_id (String)

    Path param

  • block_ms (Integer, nil)

    Query param: How long to wait for work to arrive before returning. Must be 1-999

  • reclaim_older_than_ms (Integer, nil)

    Query param: Reclaim unacknowledged work items older than this many milliseconds

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • anthropic_worker_id (String)

    Header param: Unique identifier for the specific worker polling, used to track a

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/anthropic/resources/beta/environments/work.rb', line 230

def poll(environment_id, params = {})
  query_params = [:block_ms, :reclaim_older_than_ms]
  parsed, options = Anthropic::Beta::Environments::WorkPollParams.dump_request(params)
  query = Anthropic::Internal::Util.encode_query_params(parsed.slice(*query_params))
  @client.request(
    method: :get,
    path: ["v1/environments/%1$s/work/poll?beta=true", environment_id],
    query: query,
    headers: parsed.except(*query_params).transform_keys(
      betas: "anthropic-beta",
      anthropic_worker_id: "anthropic-worker-id"
    ),
    model: Anthropic::Beta::Environments::BetaSelfHostedWork,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#retrieve(work_id, environment_id:, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::Environments::BetaSelfHostedWork

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.

Parameters:

  • work_id (String)

    Path param

  • environment_id (String)

    Path param

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/anthropic/resources/beta/environments/work.rb', line 28

def retrieve(work_id, params)
  parsed, options = Anthropic::Beta::Environments::WorkRetrieveParams.dump_request(params)
  environment_id =
    parsed.delete(:environment_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  @client.request(
    method: :get,
    path: ["v1/environments/%1$s/work/%2$s?beta=true", environment_id, work_id],
    headers: parsed.transform_keys(betas: "anthropic-beta"),
    model: Anthropic::Beta::Environments::BetaSelfHostedWork,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#stats(environment_id, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::Environments::BetaSelfHostedWorkQueueStats

Get statistics about the work queue for an environment.

Parameters:

Returns:

See Also:



260
261
262
263
264
265
266
267
268
269
# File 'lib/anthropic/resources/beta/environments/work.rb', line 260

def stats(environment_id, params = {})
  parsed, options = Anthropic::Beta::Environments::WorkStatsParams.dump_request(params)
  @client.request(
    method: :get,
    path: ["v1/environments/%1$s/work/stats?beta=true", environment_id],
    headers: parsed.transform_keys(betas: "anthropic-beta"),
    model: Anthropic::Beta::Environments::BetaSelfHostedWorkQueueStats,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#stop(work_id, environment_id:, force: nil, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::Environments::BetaSelfHostedWork

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.

Stop a work item, initiating graceful or forced shutdown.

Parameters:

  • work_id (String)

    Path param

  • environment_id (String)

    Path param

  • force (Boolean)

    Body param: If true, immediately stop work without graceful shutdown

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/anthropic/resources/beta/environments/work.rb', line 293

def stop(work_id, params)
  parsed, options = Anthropic::Beta::Environments::WorkStopParams.dump_request(params)
  environment_id =
    parsed.delete(:environment_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  header_params = {betas: "anthropic-beta"}
  @client.request(
    method: :post,
    path: ["v1/environments/%1$s/work/%2$s/stop?beta=true", environment_id, work_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Anthropic::Beta::Environments::BetaSelfHostedWork,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end

#update(work_id, environment_id:, metadata:, betas: nil, request_options: {}) ⇒ Anthropic::Models::Beta::Environments::BetaSelfHostedWork

Some parameter documentations has been truncated, see Models::Beta::Environments::WorkUpdateParams for more details.

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.

Parameters:

  • work_id (String)

    Path param

  • environment_id (String)

    Path param

  • metadata (Hash{Symbol=>String, nil})

    Body param: Metadata patch. Set a key to a string to upsert it, or to null to de

  • betas (Array<String, Symbol, Anthropic::Models::AnthropicBeta>)

    Header param: Optional header to specify the beta version(s) you want to use.

  • request_options (Anthropic::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/anthropic/resources/beta/environments/work.rb', line 68

def update(work_id, params)
  parsed, options = Anthropic::Beta::Environments::WorkUpdateParams.dump_request(params)
  environment_id =
    parsed.delete(:environment_id) do
      raise ArgumentError.new("missing required path argument #{_1}")
    end
  header_params = {betas: "anthropic-beta"}
  @client.request(
    method: :post,
    path: ["v1/environments/%1$s/work/%2$s?beta=true", environment_id, work_id],
    headers: parsed.slice(*header_params.keys).transform_keys(header_params),
    body: parsed.except(*header_params.keys),
    model: Anthropic::Beta::Environments::BetaSelfHostedWork,
    options: {extra_headers: {"anthropic-beta" => "managed-agents-2026-04-01"}, **options}
  )
end