Client
AgentBoxClient
api_key(str, optional): API key. Defaults to theGMI_AGENTBOX_API_KEYenvironment variable. RaisesValueErrorif neither is set.base_url(str, optional): API root. Defaults toGMI_AGENTBOX_BASE_URL, thenhttps://api.gmi-serving.com/v1/agents.timeout(float): Request timeout in seconds. Default30.0.
agents: Agent operations. See Agents.sandboxes: Sandbox operations by ID. See Sandboxes.snapshots: Snapshot operations by ID. See Snapshots.idcs,products: Data center and size catalog. See Catalog.
client.eligibility
Eligibility with eligible (bool) and data_centers (list).
Catalog
client.idcs.list
runtime="sandbox" for sandbox data centers.
Returns: a list of Idc, each with idc_id (use this as idc / idc_name) and name.
client.products.list
Product, each with instance_type (the size ID to launch with) and price.
Agents
client.agents.create
title(str): Agent name.runtime(str):"sandbox"for sandboxes.idc(str): Data center ID. Required whenruntime="sandbox".instance_type(str): Size ID. Required whenruntime="sandbox".image_url(str, optional): Container image.start_cmd(str, optional): Command the sandbox runs on start.env(list[dict], optional): Environment variables, each{"name", "value", "secret"}.ports(list[dict], optional): Port definitions.image_credential(dict, optional): Private registry login,{"username": ..., "secret": ...}.short_desc(str, optional): Short description.
Agent.
Raises: UnprocessableError (422) when a sandbox Agent has no idc or instance_type.
client.agents.get
client.agents.list
Page of Agent.
client.agents.update
UnprocessableError (422).
client.agents.delete
ConflictError (409) while the Agent still has sandboxes. It can still return 409 for a few seconds after the last one is deleted; retry.
Agent
Methods on
Agent:
agent.launch
pending.
Parameters
instance_type(str): Size ID. Required unlesssnapshot_idis set. Ignored whensnapshot_idis set.idc_name(str, optional): Defaults to the Agent’s data center. Must match it.env(list[dict], optional): Environment variables for this sandbox. Use"secret": Truefor secrets.display_name(str, optional): Display name.metadata(dict[str, str], optional): Your labels. Up to 32 keys; keys match^[A-Za-z0-9_.-]{1,63}$; values up to 256 characters;sourceandtask_nameare reserved.timeout_seconds(int, optional): Lifetime in seconds from launch, minimum 60. Omit for the platform default lifetime, which renews automatically. A value pins the expiry.snapshot_id(str, optional): Launch from areadysnapshot of this Agent.
Sandbox.
Raises: BadRequestError (400) for invalid metadata or a timeout under 60; NotFoundError (404) for an unknown snapshot; ConflictError (409) when the snapshot is not ready.
agent.build_logs
offset(int): Zero-based. Pass the previous page’snext_offset.limit(int): 1 to 100. Default 100.level(str, optional):debug,info,warnorerror.
BuildLogPage with entries (each offset, level, message, timestamp), next_offset and has_more.
Raises: GoneError (410) when the logs have expired.
Sandboxes
Every method below exists on aSandbox object, and on client.sandboxes with the sandbox ID as the first argument. For example, sandbox.pause() is the same as client.sandboxes.pause(sandbox_id). The exceptions are wait_until_running and refresh, which exist only on a Sandbox object.
Some collection methods return a different type:
client.sandboxes.set_timeout,pauseandresumereturnSandboxExpiry,SandboxPauseandSandboxResume, not aSandbox.client.sandboxes.create_snapshotreturns aSnapshotwith no Agent slug. Itswait_until_readyandrefreshraiseValueError. Usesandbox.create_snapshotwhen you need to wait for the snapshot.
client.sandboxes.launch
agent.launch, by Agent slug. idc_name and instance_type are required unless snapshot_id is set. A missing value raises ValueError.
client.sandboxes.list
agent_id(str, optional): Only this Agent’s sandboxes.status(str or list[str], optional): Filter by status. If omitted,stoppedanddeletedare excluded.metadata(dict[str, str], optional): Exact match; all keys must match.
Page of Sandbox.
client.sandboxes.get
sandbox.wait_until_running
running.
Raises: SandboxFailed if the status becomes error, deleted, stopped or stopping; SandboxWaitTimeout if timeout passes first.
sandbox.refresh
sandbox.set_timeout
timeout_seconds (minimum 60) and pins it. Works while the sandbox is running or paused.
Raises: BadRequestError (400) if under 60 or above your account maximum; ConflictError (409) if the sandbox is not running or paused.
sandbox.pause
pausing. Poll with refresh until paused.
Raises: ConflictError (409) if the sandbox is not running.
sandbox.resume
resuming. Poll with wait_until_running.
Parameters
timeout_seconds(int, optional): Omit to keep the run time left at pause. A value (60 or more) restarts the lifetime and pins it.
BadRequestError (400) if timeout_seconds is under 60; ConflictError (409) if the sandbox is not paused.
sandbox.execute
command(str): Command to run.wait(bool): Wait for the command to finish. DefaultTrue.wait_timeout_seconds(int, optional): How long to wait, 1 to 25. Ignored whenwait=False.
Execution. accepted is true when the command is still running.
sandbox.get_execution
sandbox.cancel_execution
sandbox.upload_file
path(str): Absolute destination path in the sandbox. No.or..segments.file(bytes, str, PathLike or binary file): Content, a local path, or an open binary file.
sandbox.download_file
FileDownload with content (bytes), filename and headers.
sandbox.shell
websocket-client connection. See Interactive shell for the message format.
sandbox.stream
StreamEvent has event, data and raw.
sandbox.create_snapshot
sandbox.metrics
NotSupportedError (501).
sandbox.delete
Sandbox
Execution
Snapshots
sandbox.create_snapshot
creating.
Parameters
name(str, optional): Up to 255 characters. If omitted, a name is generated from the sandbox name and the time.
PermissionDeniedError (403) if you are not the sandbox’s creator or an organization owner; ConflictError (409) if the sandbox is not running.
snapshot.wait_until_ready
SnapshotFailed if the status becomes error, deleting or delete_failed; SnapshotWaitTimeout if timeout passes first.
snapshot.rename
ready or error snapshot can be renamed. name is 1 to 255 characters.
Raises: BadRequestError (400) for an invalid name; ConflictError (409) while the snapshot is still creating or being deleted.
snapshot.delete
deleting.
Snapshot
Errors
Service and connection errors derive fromAgentBoxSDKError. Invalid input raises a plain ValueError. Service errors derive from APIError, which has status_code, message, code and details. See Errors and limits for the full table.