Skip to main content
Requires Python 3.9+. For workflows and examples, start with the Quickstart.

Client

AgentBoxClient

Creates a client. Parameters
  • api_key (str, optional): API key. Defaults to the GMI_AGENTBOX_API_KEY environment variable. Raises ValueError if neither is set.
  • base_url (str, optional): API root. Defaults to GMI_AGENTBOX_BASE_URL, then https://api.gmi-serving.com/v1/agents.
  • timeout (float): Request timeout in seconds. Default 30.0.
Attributes
  • 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

Returns whether your organization can launch, and in which data centers. Returns: Eligibility with eligible (bool) and data_centers (list).

Catalog

client.idcs.list

Lists data centers. Pass 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

Lists sizes available in a data center. Returns: a list of Product, each with instance_type (the size ID to launch with) and price.

Agents

client.agents.create

Creates an Agent and starts its image build. Does not start a sandbox. Parameters
  • title (str): Agent name.
  • runtime (str): "sandbox" for sandboxes.
  • idc (str): Data center ID. Required when runtime="sandbox".
  • instance_type (str): Size ID. Required when runtime="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.
Returns: Agent. Raises: UnprocessableError (422) when a sandbox Agent has no idc or instance_type.

client.agents.get

client.agents.list

Returns: Page of Agent.

client.agents.update

Updates the given fields. Locked fields raise UnprocessableError (422).

client.agents.delete

Raises: 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

Launches a sandbox and returns immediately. The sandbox starts as pending. Parameters
  • instance_type (str): Size ID. Required unless snapshot_id is set. Ignored when snapshot_id is 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": True for 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; source and task_name are 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 a ready snapshot of this Agent.
Returns: 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

Parameters
  • offset (int): Zero-based. Pass the previous page’s next_offset.
  • limit (int): 1 to 100. Default 100.
  • level (str, optional): debug, info, warn or error.
Returns: 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 a Sandbox 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, pause and resume return SandboxExpiry, SandboxPause and SandboxResume, not a Sandbox.
  • client.sandboxes.create_snapshot returns a Snapshot with no Agent slug. Its wait_until_ready and refresh raise ValueError. Use sandbox.create_snapshot when you need to wait for the snapshot.

client.sandboxes.launch

Same as 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

Parameters
  • agent_id (str, optional): Only this Agent’s sandboxes.
  • status (str or list[str], optional): Filter by status. If omitted, stopped and deleted are excluded.
  • metadata (dict[str, str], optional): Exact match; all keys must match.
Returns: Page of Sandbox.

client.sandboxes.get

sandbox.wait_until_running

Polls until the status is running. Raises: SandboxFailed if the status becomes error, deleted, stopped or stopping; SandboxWaitTimeout if timeout passes first.

sandbox.refresh

Reloads the sandbox.

sandbox.set_timeout

Sets the lifetime to now plus 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

Pauses a running sandbox. Returns when the pause is accepted; status is usually pausing. Poll with refresh until paused. Raises: ConflictError (409) if the sandbox is not running.

sandbox.resume

Resumes a paused sandbox. Returns when accepted; status is usually 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.
Raises: BadRequestError (400) if timeout_seconds is under 60; ConflictError (409) if the sandbox is not paused.

sandbox.execute

Runs a command. Parameters
  • command (str): Command to run.
  • wait (bool): Wait for the command to finish. Default True.
  • wait_timeout_seconds (int, optional): How long to wait, 1 to 25. Ignored when wait=False.
Returns: Execution. accepted is true when the command is still running.

sandbox.get_execution

sandbox.cancel_execution

sandbox.upload_file

Parameters
  • 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

Returns: FileDownload with content (bytes), filename and headers.

sandbox.shell

Opens an interactive shell. Returns a websocket-client connection. See Interactive shell for the message format.

sandbox.stream

Yields status events. Each StreamEvent has event, data and raw.

sandbox.create_snapshot

Saves a running sandbox. See Snapshots.

sandbox.metrics

Not supported on sandboxes. Raises NotSupportedError (501).

sandbox.delete

Deletes the sandbox. This cannot be undone.

Sandbox

Execution

Snapshots

sandbox.create_snapshot

Saves a running sandbox. The snapshot starts as creating. Parameters
  • name (str, optional): Up to 255 characters. If omitted, a name is generated from the sandbox name and the time.
Raises: 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

Raises: SnapshotFailed if the status becomes error, deleting or delete_failed; SnapshotWaitTimeout if timeout passes first.

snapshot.rename

Only a 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

Deletes asynchronously; status becomes deleting.

Snapshot

Errors

Service and connection errors derive from AgentBoxSDKError. 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.