Cua Docs

Pool and claim reference

Python Fleet pool configuration, claim acquisition, cleanup, and resource types in cua-sandbox 0.4.3.

Pool and Template are exported by cua_sandbox 0.4.3. These APIs use Fleet credentials independently of the legacy CUA_API_KEY flow. See configuration and authentication.

Pool.apply#

Reconciles a named Fleet pool and its template from an Image:

async def apply(
    image: Image, *, name: str, replicas: int = 1,
    cpu: int | None = None, memory_mb: int | None = None,
    services: dict[str, int] | None = None,
    autoscaling: WarmPoolAutoscaling | None = None,
    ttl_seconds_after_created: int | None = None,
) -> Pool: ...
ParameterContract
imageBuilt-in or explicit registry image accepted by the Fleet image constraints
nameRequired nonempty pool name; pool names are globally unique across accounts
replicasDesired pool replica count; default 1
cpu, memory_mbOptional template CPU and memory overrides
servicesMapping from service name to target port. If omitted or empty, uses server: 8000 and port-N: N for exposed image ports other than 8000
autoscalingOptional WarmPoolAutoscaling resource
ttl_seconds_after_createdOptional pool expiry in seconds from creation

The method reconciles the pool, then its template. If template reconciliation fails, it attempts to delete the reconciled pool. A returned Pool holds the template reference so that delete() can remove both resources.

Pool lookup, reconciliation, and deletion#

These methods use the typed Fleet requests for explicit configuration:

async def get(name: str) -> Pool: ...
async def reconcile(request: CreatePoolRequest) -> Pool: ...
async def delete(self) -> None: ...

Pool.get() retrieves an existing pool without reconciling its configuration. Pool.reconcile() requires a CreatePoolRequest instance and creates or reconciles the pool described by it. Both return a wrapper with name: str and resource, the underlying Fleet pool resource.

delete() deletes the pool. It also deletes the owned template when called on the result of Pool.apply(). A wrapper returned by get() or reconcile() does not record template ownership; manage that template separately.

PoolAccessDeniedError reports Fleet pool access denial. Choose a pool name owned by the authenticated account; an inaccessible name is not an invitation to overwrite another account's pool.

Pool.claim#

Returns an awaitable that also supports an async context manager:

def claim(
    self, *, spec: ClaimSpec | None = None, name: str | None = None,
    service: str = "server", time_to_start: float | None = None,
    ttl_seconds_after_created: int | None = None,
): ...
ParameterContract
specOptional typed claim specification
nameOptional claim identity. If a matching claim exists in the pool namespace, reconnects to it; otherwise creates it
serviceNamed service to connect to; default "server"
time_to_startOptional service readiness timeout in seconds, after claim binding
ttl_seconds_after_createdOptional claim expiry in seconds from creation; cannot be combined with an explicit spec

await pool.claim() waits for binding and service readiness, then returns a connected Sandbox. Its caller must call close() to release the claim. async with pool.claim() calls close() on exit, including when it reuses a named claim. If acquisition fails, the SDK attempts to release a claim created by that acquisition; it does not release a preexisting claim on that path.

disconnect() only drops the connection. It does not release the claim. See Sandbox lifecycle and ownership.

Pool.create_claim#

Creates a claim without waiting for binding or connecting a service:

async def create_claim(
    self, *, spec: ClaimSpec | None = None, name: str | None = None,
    ttl_seconds_after_created: int | None = None,
): ...

The returned handle has these members. Its concrete class is private; obtain it through create_claim() rather than importing the class.

MemberContract
namespace, name, pool_name, serviceClaim identity and selected service; default service is "server"
to_dict() -> dict[str, Any]Serializes identity for Sandbox.from_dict()
await wait(service=None, time_to_start=None) -> SandboxWaits for binding and service readiness and connects
await renew(shutdown_time: str) -> NoneUpdates the absolute shutdown timestamp
await release() -> NoneDeletes the claim; an already-missing claim is accepted

The caller owns cleanup after create_claim(), including when a later wait() fails. After connecting, Sandbox.close() releases the claim and disconnects.

Expiry and renewal#

The ttl_seconds_after_created convenience parameters accept integer values from 0 through 4294967295, excluding booleans. None omits the field. The schema describes the field as a creation-age TTL; accepting a value at the client does not establish the server's expiry policy. Pool and claim TTLs are configured separately. When supplying an explicit ClaimSpec, set the TTL in that spec instead of passing the convenience parameter.

Sandbox.keep_alive(minutes=...) updates the claim's absolute shutdown time. It does not reset the resource's creation timestamp. See Expire pools and claims for expiry configuration.

Template and resource types#

Template.reconcile(request: CreateTemplateRequest) is async and returns a wrapper with name and resource. TemplateResource is the underlying Fleet template type, distinct from the Template wrapper.

The following types and their named builders are reexported by cua_sandbox:

TypeMain fields or purposeBuilder
CreatePoolRequestnamespace, specCreatePoolRequestBuilder
CreateTemplateRequestnamespace, name, specCreateTemplateRequestBuilder
SandboxTemplateRefTemplate nameSandboxTemplateRefBuilder
OsGymSandboxWarmPoolSpecreplicas, sandbox_template_ref, autoscaling, ttl_seconds_after_createdOsGymSandboxWarmPoolSpecBuilder
WarmPoolAutoscalingmin_pool_size, initial_pool_size, max_pool_sizeWarmPoolAutoscalingBuilder
OsGymSandboxTemplateSpecvm_templateOsGymSandboxTemplateSpecBuilder
VmTemplateContainer disk image, runtime, resources, firmware, and servicesVmTemplateBuilder
SandboxServicename, target_port, optional protocolSandboxServiceBuilder

ClaimSpec, RuntimeKind, Firmware, and ServiceProtocol are also reexported. A ClaimSpec constructor requires keyword arguments sandbox_template_ref, warmpool, bind_deadline, and lifecycle, even when the latter three are None; ttl_seconds_after_created is optional. Builders provide named setters and build() for the types listed above.

These bindings come from the published cua-fleet 0.1.14 dependency, imported as fleet_sdk. Type availability describes the client schema; it does not establish runtime or image support on a deployment.