Skip to content

Commit 449c1b7

Browse files
committed
docs: make sandbox plugin guide developer focused
1 parent c20ce99 commit 449c1b7

2 files changed

Lines changed: 58 additions & 76 deletions

File tree

docs/en/dev/star/guides/plugin-config.md

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,9 @@ Note that `default` is only applied when creating a new config file or when a fi
226226

227227
## Building a Sandbox Runtime Plugin
228228

229-
Starting from the generic sandbox architecture, concrete runtimes such as `CUA`, `Shipyard`, `Shipyard Neo`, or `Boxlite` should be implemented as **separate plugins**, not hard-coded in AstrBot Core.
229+
A sandbox runtime plugin teaches AstrBot how to start and connect to a sandbox service. The plugin usually contains a provider, a booter/client, a config schema, and optional tools for features such as screenshots or browser control.
230230

231-
Recommended structure:
231+
Start with this structure:
232232

233233
```text
234234
data/plugins/<plugin_name>/
@@ -240,17 +240,17 @@ data/plugins/<plugin_name>/
240240
tools/
241241
```
242242

243-
Typical responsibilities are split like this:
243+
Use the files like this:
244244

245-
- `main.py`: plugin entrypoint, provider registration, and optional extra tool registration.
246-
- `provider.py`: sandbox provider implementation.
247-
- `booters/`: runtime-specific sandbox client / booter implementation.
248-
- `tools/`: optional runtime-specific tools, such as screenshot, mouse, keyboard, browser, or lifecycle helpers.
249-
- `_conf_schema.json`: provider-specific configuration shown in WebUI.
245+
- `main.py`: register the provider, and register any extra tools.
246+
- `provider.py`: adapt your runtime to AstrBot's sandbox provider methods.
247+
- `booters/`: put the client code that starts, connects to, and shuts down the sandbox.
248+
- `tools/`: add optional runtime tools such as screenshot, mouse, keyboard, browser, or lifecycle helpers.
249+
- `_conf_schema.json`: define the settings shown in WebUI.
250250

251-
### 1. Register the sandbox provider
251+
### 1. Register the provider
252252

253-
In your plugin entrypoint, register and unregister the provider through the generic sandbox APIs exposed by core:
253+
In `main.py`, create your provider and register it when the plugin loads. Pass the plugin config into the provider so `provider.py` can read values from `_conf_schema.json`.
254254

255255
```python
256256
from astrbot.api.star import Context, Star, register
@@ -274,11 +274,11 @@ class DemoSandboxPlugin(Star):
274274
unregister_sandbox_provider(self.provider.provider_id, force=True)
275275
```
276276

277-
Use a stable plugin name, directory name, and metadata `name`, ideally all aligned.
277+
Use a stable name for the plugin directory, `metadata.yaml`, and `@register(...)`. Keeping them aligned makes the generated config file easy to find.
278278

279-
### 2. Implement the provider contract
279+
### 2. Implement `provider.py`
280280

281-
Your provider should implement the generic sandbox protocol from core (`astrbot.core.computer.sandbox_provider.SandboxProvider`). In practice, that means defining:
281+
AstrBot calls the provider whenever it needs to create, reuse, rename, or destroy a sandbox. Implement these fields and methods:
282282

283283
- `provider_id`
284284
- `capabilities`
@@ -290,7 +290,7 @@ Your provider should implement the generic sandbox protocol from core (`astrbot.
290290
- `create_booter(context, session_id, sandbox_id, config)`
291291
- `destroy_booter(booter, record)`
292292

293-
Example skeleton:
293+
This is a minimal provider skeleton:
294294

295295
```python
296296
class MySandboxProvider:
@@ -329,14 +329,9 @@ class MySandboxProvider:
329329
await booter.shutdown()
330330
```
331331

332-
### 3. Put runtime-specific config in `_conf_schema.json`
332+
### 3. Add runtime config
333333

334-
Core only keeps the generic selector:
335-
336-
- `provider_settings.computer_use_runtime`
337-
- `provider_settings.sandbox.booter`
338-
339-
All runtime-specific config belongs to the plugin schema, for example:
334+
Create `_conf_schema.json` for values that users should edit in WebUI, such as API endpoints, access tokens, profiles, image names, or timeouts.
340335

341336
```json
342337
{
@@ -355,33 +350,29 @@ All runtime-specific config belongs to the plugin schema, for example:
355350
}
356351
```
357352

358-
That schema will be stored under `data/config/<plugin_name>_config.json` and passed to the plugin constructor as `config`.
353+
AstrBot stores the saved values in `data/config/<plugin_name>_config.json` and passes them to the plugin constructor as `config`.
359354

360-
If your provider needs session-level or legacy overrides from `provider_settings.sandbox`, read them in `build_create_config()` as overrides on top of the plugin config. Do not add runtime-specific fields to core config metadata.
355+
If your provider still supports older values under `provider_settings.sandbox`, read them in `build_create_config()` as overrides on top of the plugin config. New provider settings should normally live in `_conf_schema.json`.
361356

362-
### 4. Expose optional runtime tools through `tool_names`
357+
### 4. Add optional tools
363358

364-
If your runtime adds extra tools beyond the generic shell/python/filesystem stack, register them in the plugin and list their names in `tool_names`.
359+
If your runtime exposes extra abilities, register those tools in the plugin and list the tool names in `provider.tool_names`.
365360

366-
Typical examples:
361+
Common examples:
367362

368363
- screenshot tools
369364
- mouse / keyboard tools
370365
- browser tools
371366
- runtime-specific lifecycle helpers
372367

373-
Core uses `tool_names` to mount those tools automatically in sandbox mode, so avoid hard-coding provider names in core.
374-
375-
### 5. Keep runtime code out of core
376-
377-
When building a sandbox plugin:
368+
AstrBot uses `tool_names` when mounting tools in sandbox mode. Make sure the names match the tools you register in `main.py`.
378369

379-
- Put concrete runtime SDK imports in the plugin repo.
380-
- Put provider-specific defaults and config schema in the plugin repo.
381-
- Put runtime-specific tools in the plugin repo.
382-
- Keep AstrBot Core limited to generic sandbox registration, lifecycle, persistence, and dashboard/API surfaces.
370+
### 5. Try it locally
383371

384-
If you are unsure whether something belongs in core or a plugin, the rule of thumb is:
372+
After adding the plugin under `data/plugins/<plugin_name>/`, start AstrBot and check these items:
385373

386-
- generic behavior -> core
387-
- concrete runtime behavior -> plugin
374+
- The plugin loads without import errors.
375+
- The WebUI config page shows fields from `_conf_schema.json`.
376+
- The sandbox runtime selector includes your `provider_id`.
377+
- Creating a sandbox calls `create_booter()`.
378+
- Stopping or unloading the plugin calls `terminate()` and unregisters the provider.

docs/zh/dev/star/guides/plugin-config.md

Lines changed: 29 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ class ConfigPlugin(Star):
225225

226226
## 制作沙盒运行时插件
227227

228-
从通用沙盒架构开始,`CUA``Shipyard``Shipyard Neo``Boxlite` 这类具体 runtime 应当作为**独立插件**实现,而不是继续硬编码在 AstrBot Core 中
228+
沙盒运行时插件负责告诉 AstrBot 如何启动并连接到一个沙盒服务。一个插件通常包含 provider、booter/client、配置 schema,以及截图、浏览器控制这类可选工具
229229

230-
推荐目录结构
230+
可以先按这个结构创建目录
231231

232232
```text
233233
data/plugins/<plugin_name>/
@@ -239,17 +239,17 @@ data/plugins/<plugin_name>/
239239
tools/
240240
```
241241

242-
通常可以这样分工
242+
各文件大致这样分工
243243

244-
- `main.py`插件入口、provider 注册,以及可选的额外工具注册
245-
- `provider.py`:sandbox provider 实现
246-
- `booters/`runtime 具体的 sandbox client / booter
247-
- `tools/`可选的 runtime 专属工具,例如截图、鼠标、键盘、浏览器或生命周期工具
248-
- `_conf_schema.json` WebUI 中展示的 provider 专属配置
244+
- `main.py`注册 provider,也可以注册额外工具
245+
- `provider.py`把你的 runtime 适配成 AstrBot 的 sandbox provider。
246+
- `booters/`放启动、连接、关闭沙盒的 client 代码
247+
- `tools/`放截图、鼠标、键盘、浏览器或生命周期这类可选工具
248+
- `_conf_schema.json`定义 WebUI 中展示的配置项
249249

250-
### 1. 注册 sandbox provider
250+
### 1. 注册 provider
251251

252-
在插件入口中,通过 core 暴露的通用接口注册和注销 provider
252+
`main.py` 中创建 provider,并在插件加载时注册它。把插件配置传给 provider,这样 `provider.py` 就能读取 `_conf_schema.json` 生成的配置。
253253

254254
```python
255255
from astrbot.api.star import Context, Star, register
@@ -273,11 +273,11 @@ class DemoSandboxPlugin(Star):
273273
unregister_sandbox_provider(self.provider.provider_id, force=True)
274274
```
275275

276-
建议插件目录名、metadata `name`实际注册名保持一致,并使用稳定、可导入的命名
276+
建议插件目录名、`metadata.yaml` 里的 `name``@register(...)` 的名字保持一致,后续查找生成的配置文件会更直观
277277

278-
### 2. 实现 provider 协议
278+
### 2. 实现 `provider.py`
279279

280-
provider 需要实现 core 中定义的通用 sandbox 协议(`astrbot.core.computer.sandbox_provider.SandboxProvider`)。实践上至少要提供
280+
AstrBot 在创建、复用、重命名、销毁沙盒时会调用 provider。你需要实现这些字段和方法
281281

282282
- `provider_id`
283283
- `capabilities`
@@ -289,7 +289,7 @@ provider 需要实现 core 中定义的通用 sandbox 协议(`astrbot.core.com
289289
- `create_booter(context, session_id, sandbox_id, config)`
290290
- `destroy_booter(booter, record)`
291291

292-
示例骨架
292+
下面是一个最小骨架
293293

294294
```python
295295
class MySandboxProvider:
@@ -328,14 +328,9 @@ class MySandboxProvider:
328328
await booter.shutdown()
329329
```
330330

331-
### 3. runtime 专属配置放进 `_conf_schema.json`
331+
### 3. 添加 runtime 配置
332332

333-
Core 只保留通用选择项:
334-
335-
- `provider_settings.computer_use_runtime`
336-
- `provider_settings.sandbox.booter`
337-
338-
所有 runtime 专属配置都应该放在插件自己的 schema 中,例如:
333+
如果用户需要在 WebUI 中填写 API 地址、访问令牌、profile、镜像名或超时时间,把这些字段写进 `_conf_schema.json`
339334

340335
```json
341336
{
@@ -354,33 +349,29 @@ Core 只保留通用选择项:
354349
}
355350
```
356351

357-
这个 schema 会持久化到 `data/config/<plugin_name>_config.json`,并在插件实例化时作为 `config` 传入。
352+
AstrBot 会把用户保存的值写到 `data/config/<plugin_name>_config.json`,并在插件实例化时作为 `config` 传入。
358353

359-
如果 provider 需要从 `provider_settings.sandbox` 读取会话级或历史兼容覆盖项,请在 `build_create_config()` 中把它们作为插件配置之上的 override 处理。不要把 runtime 专属字段新增到 core 的配置 metadata 中
354+
如果 provider 还需要兼容旧的 `provider_settings.sandbox` 配置,可以在 `build_create_config()` 中把它们作为插件配置之上的 override。新的 provider 配置通常放在 `_conf_schema.json` 即可
360355

361-
### 4. 通过 `tool_names` 暴露可选 runtime 工具
356+
### 4. 添加可选工具
362357

363-
如果你的 runtime 除了通用 shell/python/filesystem 外,还提供额外工具,请在插件里注册这些工具,并把工具名放到 `tool_names`
358+
如果你的 runtime 除了 shell/python/filesystem 外还提供其他能力,在插件里注册对应工具,并把工具名写进 `provider.tool_names`
364359

365-
常见例子
360+
常见工具包括
366361

367362
- 截图工具
368363
- 鼠标 / 键盘工具
369364
- 浏览器工具
370365
- runtime 专属生命周期工具
371366

372-
Core 会根据 `tool_names` 自动在 sandbox mode 下挂载这些工具,因此不要在 core 中硬编码 provider 名称。
373-
374-
### 5. 让 runtime 代码留在插件里,不回流 core
375-
376-
制作沙盒插件时,请遵循下面这条边界:
367+
AstrBot 在 sandbox mode 下挂载工具时会读取 `tool_names`。这里的名字要和 `main.py` 中注册的工具名一致。
377368

378-
- 具体 runtime SDK import 放在插件仓库
379-
- provider 默认值和 schema 放在插件仓库
380-
- runtime 专属工具放在插件仓库
381-
- AstrBot Core 只负责通用注册、生命周期、持久化,以及 dashboard/API 表面
369+
### 5. 本地试跑
382370

383-
如果不确定某段逻辑该放在 core 还是插件里,可以用这个经验规则
371+
把插件放到 `data/plugins/<plugin_name>/` 后,启动 AstrBot,重点检查这些点
384372

385-
- 通用行为 -> core
386-
- 具体 runtime 行为 -> plugin
373+
- 插件加载时没有 import error。
374+
- WebUI 配置页能看到 `_conf_schema.json` 里的字段。
375+
- 沙盒 runtime 选择项里能看到你的 `provider_id`
376+
- 创建沙盒时会调用 `create_booter()`
377+
- 停止或卸载插件时会调用 `terminate()` 并注销 provider。

0 commit comments

Comments
 (0)