gmi-agentbox-sdk 0.1.0b1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gmi_agentbox_sdk-0.1.0b1/.gitignore +18 -0
- gmi_agentbox_sdk-0.1.0b1/LICENSE +21 -0
- gmi_agentbox_sdk-0.1.0b1/PKG-INFO +116 -0
- gmi_agentbox_sdk-0.1.0b1/README.md +89 -0
- gmi_agentbox_sdk-0.1.0b1/docs/reference.md +392 -0
- gmi_agentbox_sdk-0.1.0b1/docs/usage.md +269 -0
- gmi_agentbox_sdk-0.1.0b1/pyproject.toml +53 -0
- gmi_agentbox_sdk-0.1.0b1/src/agentbox_sdk/__init__.py +71 -0
- gmi_agentbox_sdk-0.1.0b1/src/agentbox_sdk/_transport.py +92 -0
- gmi_agentbox_sdk-0.1.0b1/src/agentbox_sdk/client.py +998 -0
- gmi_agentbox_sdk-0.1.0b1/src/agentbox_sdk/errors.py +102 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*.egg-info/
|
|
4
|
+
.eggs/
|
|
5
|
+
dist/
|
|
6
|
+
build/
|
|
7
|
+
.venv/
|
|
8
|
+
.pytest_cache/
|
|
9
|
+
.mypy_cache/
|
|
10
|
+
ce-tot-env
|
|
11
|
+
ie-pro-env
|
|
12
|
+
ce-tot-env.example
|
|
13
|
+
ie-pro-env.example
|
|
14
|
+
docs/todo.md
|
|
15
|
+
examples/test.py
|
|
16
|
+
.env
|
|
17
|
+
.env.*
|
|
18
|
+
!.env.example
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 GMI
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: gmi-agentbox-sdk
|
|
3
|
+
Version: 0.1.0b1
|
|
4
|
+
Summary: GMI AgentBox SDK for Python.
|
|
5
|
+
Project-URL: Homepage, https://www.gmicloud.ai/
|
|
6
|
+
Author: GMI
|
|
7
|
+
License: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Keywords: agentbox,gmi,sdk
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Requires-Dist: certifi>=2024.0.0
|
|
21
|
+
Requires-Dist: websocket-client>=1.8
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: twine>=5.0; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# GMI AgentBox SDK for Python
|
|
29
|
+
|
|
30
|
+
Thin Python client for AgentBox.
|
|
31
|
+
|
|
32
|
+
Public names are **Agent** (registered template) and **Sandbox** (launched
|
|
33
|
+
container). Registering an Agent does not start anything.
|
|
34
|
+
|
|
35
|
+
- [Usage](docs/usage.md) — install, auth, register, launch, wait, cleanup
|
|
36
|
+
- [Reference](docs/reference.md) — client, methods, models, errors
|
|
37
|
+
|
|
38
|
+
## Install
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
python -m pip install -e ".[dev]"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Requires Python 3.9+.
|
|
45
|
+
|
|
46
|
+
## Auth
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
export GMI_AGENTBOX_API_KEY="your-api-key"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
`GMI_AGENTBOX_API_KEY` is required (or pass `api_key=`).
|
|
53
|
+
`GMI_AGENTBOX_BASE_URL` is optional and defaults to production
|
|
54
|
+
`https://console.gmicloud.ai`.
|
|
55
|
+
|
|
56
|
+
## Quickstart
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from agentbox_sdk import AgentBoxClient
|
|
60
|
+
|
|
61
|
+
client = AgentBoxClient()
|
|
62
|
+
|
|
63
|
+
# Discover available IDCs and SKUs, then pass explicit values.
|
|
64
|
+
# The SDK does not pick IDC or instance_type for you.
|
|
65
|
+
idc_id = "us-central-iowa1"
|
|
66
|
+
instance_type = "gmi.container.intel.x4660.large"
|
|
67
|
+
|
|
68
|
+
agent = client.agents.create(
|
|
69
|
+
title="agentbox-demo",
|
|
70
|
+
image_url="docker.io/library/alpine:3.20",
|
|
71
|
+
idc=idc_id,
|
|
72
|
+
)
|
|
73
|
+
# generated_api_key is plaintext only on this response
|
|
74
|
+
|
|
75
|
+
sandbox = agent.launch(instance_type=instance_type)
|
|
76
|
+
sandbox.wait_until_running() # default timeout 300s
|
|
77
|
+
print(sandbox.endpoint_url)
|
|
78
|
+
|
|
79
|
+
print(sandbox.logs())
|
|
80
|
+
sandbox.delete()
|
|
81
|
+
agent.delete() # does not stop remaining sandboxes
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`GET /products?idc_name=` takes an **idcId** from `GET /idcs`, not a region
|
|
85
|
+
label. Launch cannot change the Agent's IDC.
|
|
86
|
+
|
|
87
|
+
`sandboxes.list()` omits `stopped` and `deleted` unless you pass `status`.
|
|
88
|
+
|
|
89
|
+
Against production (bills the account):
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
set -a && source ./ie-pro-env && set +a
|
|
93
|
+
PYTHONPATH=src python examples/live_smoke.py
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
For the runtime E2E (build, command execution, file round trip, and
|
|
97
|
+
asynchronous cancellation), select a matching runtime/IDC/SKU and run:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
export GMI_AGENTBOX_RUNTIME="sandbox" # or "container"
|
|
101
|
+
PYTHONPATH=src python examples/sandbox_e2e.py
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`GMI_AGENTBOX_BASE_URL` is optional. The E2E defaults
|
|
105
|
+
`GMI_AGENTBOX_RUNTIME` to `sandbox`; `GMI_AGENTBOX_IDC` and
|
|
106
|
+
`GMI_AGENTBOX_INSTANCE_TYPE` must always be set to values for the selected
|
|
107
|
+
runtime.
|
|
108
|
+
|
|
109
|
+
Set `GMI_AGENTBOX_TEST_SHELL=1` to include a WebSocket shell-connect check.
|
|
110
|
+
The E2E asserts its data-plane operations for either runtime; it does not skip
|
|
111
|
+
them according to Sandbox capabilities. Set `GMI_AGENTBOX_VALIDATE_CATALOGUE=1`
|
|
112
|
+
to enable the optional runtime eligibility/IDC/SKU preflight.
|
|
113
|
+
|
|
114
|
+
Sandbox runtimes also support command execution, file upload/download, and an
|
|
115
|
+
interactive WebSocket shell. See the reference for `sandbox.execute()`,
|
|
116
|
+
`sandbox.upload_file()`, `sandbox.download_file()`, and `sandbox.shell()`.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# GMI AgentBox SDK for Python
|
|
2
|
+
|
|
3
|
+
Thin Python client for AgentBox.
|
|
4
|
+
|
|
5
|
+
Public names are **Agent** (registered template) and **Sandbox** (launched
|
|
6
|
+
container). Registering an Agent does not start anything.
|
|
7
|
+
|
|
8
|
+
- [Usage](docs/usage.md) — install, auth, register, launch, wait, cleanup
|
|
9
|
+
- [Reference](docs/reference.md) — client, methods, models, errors
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
python -m pip install -e ".[dev]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Requires Python 3.9+.
|
|
18
|
+
|
|
19
|
+
## Auth
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
export GMI_AGENTBOX_API_KEY="your-api-key"
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
`GMI_AGENTBOX_API_KEY` is required (or pass `api_key=`).
|
|
26
|
+
`GMI_AGENTBOX_BASE_URL` is optional and defaults to production
|
|
27
|
+
`https://console.gmicloud.ai`.
|
|
28
|
+
|
|
29
|
+
## Quickstart
|
|
30
|
+
|
|
31
|
+
```python
|
|
32
|
+
from agentbox_sdk import AgentBoxClient
|
|
33
|
+
|
|
34
|
+
client = AgentBoxClient()
|
|
35
|
+
|
|
36
|
+
# Discover available IDCs and SKUs, then pass explicit values.
|
|
37
|
+
# The SDK does not pick IDC or instance_type for you.
|
|
38
|
+
idc_id = "us-central-iowa1"
|
|
39
|
+
instance_type = "gmi.container.intel.x4660.large"
|
|
40
|
+
|
|
41
|
+
agent = client.agents.create(
|
|
42
|
+
title="agentbox-demo",
|
|
43
|
+
image_url="docker.io/library/alpine:3.20",
|
|
44
|
+
idc=idc_id,
|
|
45
|
+
)
|
|
46
|
+
# generated_api_key is plaintext only on this response
|
|
47
|
+
|
|
48
|
+
sandbox = agent.launch(instance_type=instance_type)
|
|
49
|
+
sandbox.wait_until_running() # default timeout 300s
|
|
50
|
+
print(sandbox.endpoint_url)
|
|
51
|
+
|
|
52
|
+
print(sandbox.logs())
|
|
53
|
+
sandbox.delete()
|
|
54
|
+
agent.delete() # does not stop remaining sandboxes
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`GET /products?idc_name=` takes an **idcId** from `GET /idcs`, not a region
|
|
58
|
+
label. Launch cannot change the Agent's IDC.
|
|
59
|
+
|
|
60
|
+
`sandboxes.list()` omits `stopped` and `deleted` unless you pass `status`.
|
|
61
|
+
|
|
62
|
+
Against production (bills the account):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
set -a && source ./ie-pro-env && set +a
|
|
66
|
+
PYTHONPATH=src python examples/live_smoke.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
For the runtime E2E (build, command execution, file round trip, and
|
|
70
|
+
asynchronous cancellation), select a matching runtime/IDC/SKU and run:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
export GMI_AGENTBOX_RUNTIME="sandbox" # or "container"
|
|
74
|
+
PYTHONPATH=src python examples/sandbox_e2e.py
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
`GMI_AGENTBOX_BASE_URL` is optional. The E2E defaults
|
|
78
|
+
`GMI_AGENTBOX_RUNTIME` to `sandbox`; `GMI_AGENTBOX_IDC` and
|
|
79
|
+
`GMI_AGENTBOX_INSTANCE_TYPE` must always be set to values for the selected
|
|
80
|
+
runtime.
|
|
81
|
+
|
|
82
|
+
Set `GMI_AGENTBOX_TEST_SHELL=1` to include a WebSocket shell-connect check.
|
|
83
|
+
The E2E asserts its data-plane operations for either runtime; it does not skip
|
|
84
|
+
them according to Sandbox capabilities. Set `GMI_AGENTBOX_VALIDATE_CATALOGUE=1`
|
|
85
|
+
to enable the optional runtime eligibility/IDC/SKU preflight.
|
|
86
|
+
|
|
87
|
+
Sandbox runtimes also support command execution, file upload/download, and an
|
|
88
|
+
interactive WebSocket shell. See the reference for `sandbox.execute()`,
|
|
89
|
+
`sandbox.upload_file()`, `sandbox.download_file()`, and `sandbox.shell()`.
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
# Reference
|
|
2
|
+
|
|
3
|
+
Package: `gmi-agentbox-sdk`
|
|
4
|
+
Import: `agentbox_sdk`
|
|
5
|
+
|
|
6
|
+
See [Usage](usage.md) for workflows.
|
|
7
|
+
|
|
8
|
+
## Configuration
|
|
9
|
+
|
|
10
|
+
### `AgentBoxClient`
|
|
11
|
+
|
|
12
|
+
```python
|
|
13
|
+
AgentBoxClient(
|
|
14
|
+
api_key: str | None = None,
|
|
15
|
+
base_url: str | None = None,
|
|
16
|
+
*,
|
|
17
|
+
timeout: float = 30.0,
|
|
18
|
+
)
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
| Argument | Default | Notes |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `api_key` | `GMI_AGENTBOX_API_KEY` | Required API key. Raises `ValueError` if unset |
|
|
24
|
+
| `base_url` | `GMI_AGENTBOX_BASE_URL` or `DEFAULT_BASE_URL` | Optional service origin. Production origin if unset |
|
|
25
|
+
| `timeout` | `30.0` | Per HTTP call, seconds |
|
|
26
|
+
|
|
27
|
+
`DEFAULT_BASE_URL` is
|
|
28
|
+
`https://console.gmicloud.ai`.
|
|
29
|
+
`DEFAULT_WAIT_TIMEOUT` is `300.0` seconds (`sandbox.wait_until_running`).
|
|
30
|
+
|
|
31
|
+
Collections on the client: `agents`, `sandboxes`, `idcs`, `products`.
|
|
32
|
+
Also `client.eligibility()`.
|
|
33
|
+
|
|
34
|
+
#### `client.health() -> dict`
|
|
35
|
+
|
|
36
|
+
Returns local client configuration.
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
{"status": "ok", "baseUrl": "...", "authenticated": True}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
#### `client.eligibility() -> Eligibility`
|
|
43
|
+
|
|
44
|
+
Returns the organization's available runtimes and data centers.
|
|
45
|
+
|
|
46
|
+
### Environment variables
|
|
47
|
+
|
|
48
|
+
| Variable | Used by |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `GMI_AGENTBOX_API_KEY` | Required API key |
|
|
51
|
+
| `GMI_AGENTBOX_BASE_URL` | Optional service origin; defaults to `DEFAULT_BASE_URL` |
|
|
52
|
+
|
|
53
|
+
Errors expose `message`, `code`, and `details` when supplied by the service.
|
|
54
|
+
|
|
55
|
+
## Agents
|
|
56
|
+
|
|
57
|
+
### `client.agents`
|
|
58
|
+
|
|
59
|
+
#### `create(*, title, ...) -> Agent`
|
|
60
|
+
|
|
61
|
+
| Parameter | Required | Details |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `title` | yes | Agent name |
|
|
64
|
+
| `image_url` | no | Container image |
|
|
65
|
+
| `idc` | Sandbox: yes; otherwise no | Data center identifier; required with `runtime="sandbox"` |
|
|
66
|
+
| `runtime` | no | `"container"` or `"sandbox"`; defaults to the service default |
|
|
67
|
+
| `start_cmd` | no | Startup command for a Sandbox |
|
|
68
|
+
| `env` | no | Environment-variable definitions |
|
|
69
|
+
| `ports` | no | Port definitions |
|
|
70
|
+
| `instance_type` | Sandbox: yes; otherwise no | Required with `runtime="sandbox"` |
|
|
71
|
+
| `assign_public_ip` | no | Whether to request a public IP |
|
|
72
|
+
| `image_credential` | no | Private-registry credentials: `{"username": "...", "secret": "..."}` |
|
|
73
|
+
| `short_desc` | no | Short description |
|
|
74
|
+
| `share_storage_mount_path` | no | Shared-storage mount path |
|
|
75
|
+
| `clone_source_id` | no | Source Agent ID to clone |
|
|
76
|
+
|
|
77
|
+
Create does not start a container.
|
|
78
|
+
|
|
79
|
+
#### `list(*, page=1, page_size=20) -> Page`
|
|
80
|
+
|
|
81
|
+
Pagination is 1-indexed. API default page size is 20, max 100.
|
|
82
|
+
|
|
83
|
+
#### `get(slug) -> Agent`
|
|
84
|
+
|
|
85
|
+
#### `update(slug, **fields) -> Agent`
|
|
86
|
+
|
|
87
|
+
PATCH passthrough. Only send fields the API accepts; locked fields return `422`.
|
|
88
|
+
|
|
89
|
+
#### `delete(slug) -> None`
|
|
90
|
+
|
|
91
|
+
Does not stop or delete running sandboxes of that Agent.
|
|
92
|
+
|
|
93
|
+
### `Agent`
|
|
94
|
+
|
|
95
|
+
Represents an Agent.
|
|
96
|
+
|
|
97
|
+
| Property | Type | Notes |
|
|
98
|
+
|---|---|---|
|
|
99
|
+
| `id` | `str` | Agent ID |
|
|
100
|
+
| `slug` | `str` | Stable Agent identifier |
|
|
101
|
+
| `title` | `str \| None` | |
|
|
102
|
+
| `idc` | `str \| None` | Data center identifier |
|
|
103
|
+
| `image_url` | `str \| None` | |
|
|
104
|
+
| `runtime` | `str \| None` | Selected runtime |
|
|
105
|
+
| `template_build_status` | `str \| None` | Sandbox image-build status |
|
|
106
|
+
| `template_build_error` | `str \| None` | Sandbox image-build error |
|
|
107
|
+
| `env` | `list` | Copy of `env` |
|
|
108
|
+
| `revision` | `int \| None` | |
|
|
109
|
+
| `generated_api_key` | `str \| None` | Plaintext MaaS key on **create** only |
|
|
110
|
+
| `launchable` | `bool` | Whether the Agent can be launched |
|
|
111
|
+
|
|
112
|
+
#### `agent.refresh() -> Agent`
|
|
113
|
+
|
|
114
|
+
Reloads the Agent.
|
|
115
|
+
|
|
116
|
+
#### `agent.update(**fields) -> Agent`
|
|
117
|
+
|
|
118
|
+
Same as `client.agents.update(agent.slug, **fields)`.
|
|
119
|
+
|
|
120
|
+
#### `agent.delete() -> None`
|
|
121
|
+
|
|
122
|
+
#### `agent.launch(*, instance_type, idc_name=None, env=None, display_name=None, assign_public_ip=None, ports=None, storages=None) -> Sandbox`
|
|
123
|
+
|
|
124
|
+
`idc_name` defaults to `agent.idc`. Raises `ValueError` if neither is set.
|
|
125
|
+
Launch cannot change region; `idc_name` must match the Agent's data center.
|
|
126
|
+
|
|
127
|
+
Launch returns immediately. Call `refresh()` or `wait_until_running()` for
|
|
128
|
+
current state.
|
|
129
|
+
|
|
130
|
+
#### `agent.sandboxes(*, page=1, page_size=20) -> Page`
|
|
131
|
+
|
|
132
|
+
Sandboxes for this Agent.
|
|
133
|
+
|
|
134
|
+
## Sandboxes
|
|
135
|
+
|
|
136
|
+
### `client.sandboxes`
|
|
137
|
+
|
|
138
|
+
#### `launch(slug, *, instance_type, idc_name, ...) -> Sandbox`
|
|
139
|
+
|
|
140
|
+
Same body as `agent.launch`. `idc_name` is required here.
|
|
141
|
+
|
|
142
|
+
#### `list(*, agent_id=None, status=None, page=1, page_size=20) -> Page`
|
|
143
|
+
|
|
144
|
+
| Parameter | Query |
|
|
145
|
+
|---|---|
|
|
146
|
+
| `agent_id` | Restrict results to one Agent |
|
|
147
|
+
| `status` | `status`; a sequence is joined with commas |
|
|
148
|
+
| `page` / `page_size` | pagination |
|
|
149
|
+
|
|
150
|
+
If `status` is omitted, the API **excludes** `stopped` and `deleted`.
|
|
151
|
+
|
|
152
|
+
#### `get(sandbox_id) -> Sandbox`
|
|
153
|
+
|
|
154
|
+
#### `delete(sandbox_id) -> None`
|
|
155
|
+
|
|
156
|
+
One-way. The sandbox cannot be restarted.
|
|
157
|
+
|
|
158
|
+
#### `logs(sandbox_id) -> str`
|
|
159
|
+
|
|
160
|
+
Returns the `logs` string from the response payload, or `""`.
|
|
161
|
+
|
|
162
|
+
#### `metrics(sandbox_id, *, start, end, kinds=None, step=None) -> MetricsBatch`
|
|
163
|
+
|
|
164
|
+
`start` / `end` are unix seconds. `kinds` is
|
|
165
|
+
a string or sequence (`cpu,memory`); omit for all 8 charts. `step` default
|
|
166
|
+
on the API is 60s (min 5, max 3600).
|
|
167
|
+
|
|
168
|
+
#### `metrics_timeseries(sandbox_id, *, kind, start, end, step=None) -> MetricSeries`
|
|
169
|
+
|
|
170
|
+
`kind` is one of `gpu_util`,
|
|
171
|
+
`gpu_mem`, `cpu`, `memory`, `disk_read`, `disk_write`, `net_rx`, `net_tx`.
|
|
172
|
+
|
|
173
|
+
#### `stream(sandbox_id, *, timeout=None) -> Iterator[StreamEvent]`
|
|
174
|
+
|
|
175
|
+
Yields `StreamEvent(event, data, raw)`.
|
|
176
|
+
Comment lines (`: ping`) are `event="heartbeat"`. `timeout=None` means the
|
|
177
|
+
socket has no idle timeout. 4xx/5xx raise the same `APIError` types as
|
|
178
|
+
other calls.
|
|
179
|
+
|
|
180
|
+
Logs, metrics, and stream methods require the corresponding Sandbox
|
|
181
|
+
capability to be available.
|
|
182
|
+
|
|
183
|
+
#### `execute(sandbox_id, command, *, wait=True, wait_timeout_seconds=None) -> Execution`
|
|
184
|
+
|
|
185
|
+
Runs a command in a Sandbox. A completed command returns `accepted=False`; an
|
|
186
|
+
accepted asynchronous command returns `accepted=True`.
|
|
187
|
+
|
|
188
|
+
#### `get_execution(sandbox_id, execution_id) -> Execution`
|
|
189
|
+
|
|
190
|
+
Retrieves the latest execution state.
|
|
191
|
+
|
|
192
|
+
#### `cancel_execution(sandbox_id, execution_id) -> Execution`
|
|
193
|
+
|
|
194
|
+
Requests cancellation of an execution.
|
|
195
|
+
|
|
196
|
+
#### `upload_file(sandbox_id, *, path, file) -> list[dict]`
|
|
197
|
+
|
|
198
|
+
Uploads bytes, a local path, or a binary file object to an absolute Sandbox
|
|
199
|
+
path.
|
|
200
|
+
|
|
201
|
+
#### `download_file(sandbox_id, *, path) -> FileDownload`
|
|
202
|
+
|
|
203
|
+
Downloads a file from an absolute Sandbox path.
|
|
204
|
+
|
|
205
|
+
#### `shell(sandbox_id, *, timeout=None)`
|
|
206
|
+
|
|
207
|
+
Opens an interactive shell connection.
|
|
208
|
+
|
|
209
|
+
### `Sandbox`
|
|
210
|
+
|
|
211
|
+
Represents a Sandbox.
|
|
212
|
+
|
|
213
|
+
| Property | Type | Notes |
|
|
214
|
+
|---|---|---|
|
|
215
|
+
| `id` | `str` | Sandbox ID |
|
|
216
|
+
| `status` | `str \| None` | Current lifecycle status |
|
|
217
|
+
| `endpoint_url` | `str \| None` | Empty string becomes `None` |
|
|
218
|
+
| `agent_id` | `str \| None` | Owning Agent ID |
|
|
219
|
+
| `agent_slug` | `str \| None` | Owning Agent slug |
|
|
220
|
+
| `display_name` | `str \| None` | |
|
|
221
|
+
| `instance_type` | `str \| None` | Billing SKU, not the product object name |
|
|
222
|
+
| `idc_name` | `str \| None` | Data center identifier |
|
|
223
|
+
| `status_stale` | `bool` | |
|
|
224
|
+
| `last_error` | `str \| None` | |
|
|
225
|
+
| `runtime` | `str \| None` | Runtime name, e.g. `sandbox` |
|
|
226
|
+
| `capabilities` | `dict` | Server-derived enabled surfaces |
|
|
227
|
+
| `expires_at` | `str \| None` | Sandbox expiry timestamp |
|
|
228
|
+
|
|
229
|
+
#### `sandbox.refresh() -> Sandbox`
|
|
230
|
+
|
|
231
|
+
#### `sandbox.logs() -> str`
|
|
232
|
+
|
|
233
|
+
#### `sandbox.metrics(*, start, end, kinds=None, step=None) -> MetricsBatch`
|
|
234
|
+
|
|
235
|
+
#### `sandbox.metrics_timeseries(*, kind, start, end, step=None) -> MetricSeries`
|
|
236
|
+
|
|
237
|
+
#### `sandbox.stream(*, timeout=None) -> Iterator[StreamEvent]`
|
|
238
|
+
|
|
239
|
+
#### `sandbox.execute(command, *, wait=True, wait_timeout_seconds=None) -> Execution`
|
|
240
|
+
|
|
241
|
+
Runs a command. `Execution.accepted` is true when execution continues
|
|
242
|
+
asynchronously; use `get_execution()` to poll it, or `cancel_execution()`
|
|
243
|
+
to request cancellation. `wait_timeout_seconds` is omitted when `wait=False`.
|
|
244
|
+
|
|
245
|
+
#### `sandbox.get_execution(execution_id) -> Execution`
|
|
246
|
+
|
|
247
|
+
#### `sandbox.cancel_execution(execution_id) -> Execution`
|
|
248
|
+
|
|
249
|
+
#### `sandbox.upload_file(path, file) -> list[dict]`
|
|
250
|
+
|
|
251
|
+
Accepts bytes, a local
|
|
252
|
+
path, or a binary file object. `sandbox.download_file(path=...)` returns
|
|
253
|
+
`FileDownload(content, filename, headers)`. Paths must be absolute and cannot
|
|
254
|
+
contain `.` or `..` segments.
|
|
255
|
+
|
|
256
|
+
#### `sandbox.download_file(path) -> FileDownload`
|
|
257
|
+
|
|
258
|
+
#### `sandbox.shell(*, timeout=None)`
|
|
259
|
+
|
|
260
|
+
Returns an interactive connection supporting `send`, `recv`, and `close`.
|
|
261
|
+
|
|
262
|
+
#### `sandbox.delete() -> None`
|
|
263
|
+
|
|
264
|
+
#### `sandbox.wait_until_running(*, timeout=300.0, poll_interval=2.0) -> Sandbox`
|
|
265
|
+
|
|
266
|
+
Polls until `status == "running"`.
|
|
267
|
+
|
|
268
|
+
| Outcome | Result |
|
|
269
|
+
|---|---|
|
|
270
|
+
| `running` | returns `self` |
|
|
271
|
+
| `error`, `deleted`, `stopped`, `stopping` | raises `SandboxFailed` |
|
|
272
|
+
| timeout | raises `SandboxWaitTimeout` |
|
|
273
|
+
|
|
274
|
+
`SandboxFailed.status` is the sandbox status; `SandboxFailed.message` is
|
|
275
|
+
`last_error` when set.
|
|
276
|
+
|
|
277
|
+
## Catalog
|
|
278
|
+
|
|
279
|
+
### `client.idcs`
|
|
280
|
+
|
|
281
|
+
#### `list(*, runtime=None) -> list[Idc]`
|
|
282
|
+
|
|
283
|
+
### `Idc`
|
|
284
|
+
|
|
285
|
+
| Property | Description |
|
|
286
|
+
|---|---|
|
|
287
|
+
| `idc_id` | Data center identifier |
|
|
288
|
+
| `name` | `name` |
|
|
289
|
+
|
|
290
|
+
Use `idc_id` when selecting an Agent or Sandbox location.
|
|
291
|
+
|
|
292
|
+
### `client.products`
|
|
293
|
+
|
|
294
|
+
#### `list(*, idc_name=None, runtime=None) -> list[Product]`
|
|
295
|
+
|
|
296
|
+
`idc_name` is a data center identifier from `idcs.list()`, not a region label.
|
|
297
|
+
|
|
298
|
+
### `Product`
|
|
299
|
+
|
|
300
|
+
| Property | Description |
|
|
301
|
+
|---|---|
|
|
302
|
+
| `instance_type` | SKU identifier |
|
|
303
|
+
| `price` | `price` |
|
|
304
|
+
|
|
305
|
+
## Result types
|
|
306
|
+
|
|
307
|
+
### `Page`
|
|
308
|
+
|
|
309
|
+
```python
|
|
310
|
+
@dataclass
|
|
311
|
+
class Page:
|
|
312
|
+
items: list # Agent or Sandbox
|
|
313
|
+
total: int
|
|
314
|
+
page: int
|
|
315
|
+
page_size: int
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### `Execution`
|
|
319
|
+
|
|
320
|
+
| Property | Type | Description |
|
|
321
|
+
|---|---|---|
|
|
322
|
+
| `id` | `str \| None` | Execution identifier |
|
|
323
|
+
| `status` | `str \| None` | Current execution status |
|
|
324
|
+
| `exit_code` | `int \| None` | Process exit code when complete |
|
|
325
|
+
| `accepted` | `bool` | True when execution continues asynchronously |
|
|
326
|
+
| `data` | `dict` | Execution details, including command output when provided |
|
|
327
|
+
|
|
328
|
+
### `FileDownload`
|
|
329
|
+
|
|
330
|
+
| Property | Type | Description |
|
|
331
|
+
|---|---|---|
|
|
332
|
+
| `content` | `bytes` | Downloaded file content |
|
|
333
|
+
| `filename` | `str \| None` | Download filename |
|
|
334
|
+
| `headers` | mapping | Response metadata |
|
|
335
|
+
|
|
336
|
+
## Errors
|
|
337
|
+
|
|
338
|
+
All SDK errors subclass `AgentBoxSDKError`.
|
|
339
|
+
|
|
340
|
+
| Type | When |
|
|
341
|
+
|---|---|
|
|
342
|
+
| `TransportError` | The service could not be reached |
|
|
343
|
+
| `APIError` | A service error not mapped below |
|
|
344
|
+
| `BadRequestError` | Invalid request |
|
|
345
|
+
| `AuthenticationError` | Invalid or missing API key |
|
|
346
|
+
| `PermissionDeniedError` | Insufficient permission |
|
|
347
|
+
| `NotFoundError` | Requested resource was not found |
|
|
348
|
+
| `ConflictError` | Request conflicts with resource state |
|
|
349
|
+
| `UnprocessableError` | Request could not be processed |
|
|
350
|
+
| `RateLimitError` | Too many requests |
|
|
351
|
+
| `ServerError` | Service-side failure |
|
|
352
|
+
| `SandboxFailed` | Wait hit a terminal non-running status |
|
|
353
|
+
| `SandboxWaitTimeout` | Wait exceeded `timeout` |
|
|
354
|
+
|
|
355
|
+
`APIError` attributes: `status_code`, `message`, `code`, `details`.
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
## Public exports
|
|
359
|
+
|
|
360
|
+
```python
|
|
361
|
+
from agentbox_sdk import (
|
|
362
|
+
DEFAULT_BASE_URL,
|
|
363
|
+
Agent,
|
|
364
|
+
AgentBoxClient,
|
|
365
|
+
AgentBoxSDKError,
|
|
366
|
+
APIError,
|
|
367
|
+
AuthenticationError,
|
|
368
|
+
BadRequestError,
|
|
369
|
+
ConflictError,
|
|
370
|
+
Eligibility,
|
|
371
|
+
Execution,
|
|
372
|
+
FileDownload,
|
|
373
|
+
Idc,
|
|
374
|
+
MetricSeries,
|
|
375
|
+
MetricsBatch,
|
|
376
|
+
NotFoundError,
|
|
377
|
+
Page,
|
|
378
|
+
PermissionDeniedError,
|
|
379
|
+
Product,
|
|
380
|
+
RateLimitError,
|
|
381
|
+
Sandbox,
|
|
382
|
+
SandboxFailed,
|
|
383
|
+
SandboxWaitTimeout,
|
|
384
|
+
ServerError,
|
|
385
|
+
StreamEvent,
|
|
386
|
+
TransportError,
|
|
387
|
+
UnprocessableError,
|
|
388
|
+
)
|
|
389
|
+
```
|
|
390
|
+
|
|
391
|
+
`__version__` is the installed `gmi-agentbox-sdk` version, or `"0.0.0"` if
|
|
392
|
+
the package metadata is missing.
|