AS AgentScopeAPI 手册 / API Reference

BrowserSandbox

@RegisterSandbox( imageName = "agentscope-registry.ap-southeast-1.cr.aliyuncs.com/agentscope/runtime-sandbox-browser:latest", sandboxType = "browser", securityLevel = "medium", timeout = 60, description = "Browser sandbox" ) public class BrowserSandbox extends Sandbox
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:26–244

Browser 沙箱,承载智能体的部署、调度与服务化运行。位于 io.agentscope.runtime.sandbox.box 包,继承自 Sandbox。核心成员包括 getDesktopUrl、navigate、click、type、takeScreenshot、snapshot。

A class in io.agentscope.runtime.sandbox.box that deploys, schedules and serves agents. Declared in io.agentscope.runtime.sandbox.box. Extends Sandbox.

构造器摘要Constructor Summary

构造器Constructor说明Description
public BrowserSandbox(SandboxService managerApi, String userId, String sessionId)
初始化 `BrowserSandbox` 实例。
Creates a new instance.
public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, String baseUrl)
初始化 `BrowserSandbox` 实例。
Creates a new instance.
public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, FileSystemConfig fileSystemConfig)
初始化 `BrowserSandbox` 实例。
Creates a new instance.
public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, Map<String, String> environment)
初始化 `BrowserSandbox` 实例。
Creates a new instance.
public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, String baseUrl, FileSystemConfig fileSystemConfig, Map<String, String> environment)
初始化 `BrowserSandbox` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
public String getDesktopUrl()
获取 `getDesktopUrl`。
Get the desktop URL for VNC access.
public String navigate(String url)
设置该参数。
Performs the navigate operation.
public String click(String element, String ref)
执行 `click` 方法。
Performs the click operation.
public String type(String element, String ref, String text)
执行类型相关操作。
Performs the type operation.
public String type(String element, String ref, String text, Boolean submit, Boolean slowly)
执行类型相关操作。
Performs the type operation.
public String takeScreenshot()
返回 `takeScreenshot` 结果。
Returns the take screenshot.
public String takeScreenshot(Boolean raw, String filename, String element, String ref)
执行 `takeScreenshot` 方法。
Performs the take screenshot operation.
public String snapshot()
返回快照。
Returns the snapshot.
public String tabNew(String url)
设置该参数。
Performs the tab new operation.
public String tabSelect(Integer index)
设置该参数。
Performs the tab select operation.
public String tabClose(Integer index)
设置该参数。
Performs the tab close operation.
public String tabList()
返回 `tabList` 结果。
Returns the tab list.
public String waitFor(Double time)
等待用于。
Performs the wait for operation.
public String waitFor(Double time, String text, String textGone)
等待用于。
Performs the wait for operation.
public String resize(Double width, Double height)
执行 `resize` 方法。
Performs the resize operation.
public String closeBrowser()
关闭 `closeBrowser`。
Closes the browser.
public String consoleMessages()
返回控制台消息。
Returns the console messages.
public String networkRequests()
返回 `networkRequests` 结果。
Returns the network requests.
public String navigateBack()
返回 `navigateBack` 结果。
Returns the navigate back.
public String navigateForward()
返回 `navigateForward` 结果。
Returns the navigate forward.
public String hover(String element, String ref)
执行 `hover` 方法。
Performs the hover operation.
public String pressKey(String key)
设置该参数。
Performs the press key operation.
public String handleDialog(Boolean accept, String promptText)
处理 `handleDialog`。
Performs the handle dialog operation.
public String fileUpload(String[] paths)
设置文件上传。
Performs the file upload operation.
public String pdfSave(String filename)
设置该参数。
Performs the pdf save operation.
public String drag(String startElement, String startRef, String endElement, String endRef)
执行 `drag` 方法。
Performs the drag operation.
public String selectOption(String element, String ref, String[] values)
执行选择选项相关操作。
Performs the select option operation.

构造器详情Constructor Detail

BrowserSandbox

public BrowserSandbox(SandboxService managerApi, String userId, String sessionId)

初始化 BrowserSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerApiSandboxService管理器 API(类型 `SandboxService`)。The manager api.
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:37–39

BrowserSandbox

public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, String baseUrl)

初始化 BrowserSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerApiSandboxService管理器 API(类型 `SandboxService`)。The manager api.
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
baseUrlString基类 URL(类型 `String`)。The base url.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:41–47

BrowserSandbox

public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, FileSystemConfig fileSystemConfig)

初始化 BrowserSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerApiSandboxService管理器 API(类型 `SandboxService`)。The manager api.
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
fileSystemConfigFileSystemConfig文件系统配置(类型 `FileSystemConfig`)。The file system config.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:49–55

BrowserSandbox

public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, Map<String, String> environment)

初始化 BrowserSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerApiSandboxService管理器 API(类型 `SandboxService`)。The manager api.
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
environmentMap<String, String>环境(类型 `Map`)。The environment.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:57–63

BrowserSandbox

public BrowserSandbox(SandboxService managerApi, String userId, String sessionId, String baseUrl, FileSystemConfig fileSystemConfig, Map<String, String> environment)

初始化 BrowserSandbox 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
managerApiSandboxService管理器 API(类型 `SandboxService`)。The manager api.
userIdString用户标识(类型 `String`)。The user id.
sessionIdString会话标识(类型 `String`)。The session id.
baseUrlString基类 URL(类型 `String`)。The base url.
fileSystemConfigFileSystemConfig文件系统配置(类型 `FileSystemConfig`)。The file system config.
environmentMap<String, String>环境(类型 `Map`)。The environment.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:65–74

方法详情Method Detail

getDesktopUrl

public String getDesktopUrl()

获取 getDesktopUrl。

Get the desktop URL for VNC access.

返回Returns String
返回字符串结果。The desktop URL for VNC access
抛出Throws
  • RuntimeException 可能抛出 `RuntimeException`。if sandbox is not healthy
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:83–85

click

public String click(String element, String ref)

执行 click 方法。

Performs the click operation.

参数Parameters
名称Name类型Type说明Description
elementStringelement(类型 `String`)。The element.
refString引用(类型 `String`)。The ref.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:93–98

type

public String type(String element, String ref, String text)

执行类型相关操作。

Performs the type operation.

参数Parameters
名称Name类型Type说明Description
elementStringelement(类型 `String`)。The element.
refString引用(类型 `String`)。The ref.
textString文本(类型 `String`)。The text.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:100–102

type

public String type(String element, String ref, String text, Boolean submit, Boolean slowly)

执行类型相关操作。

Performs the type operation.

参数Parameters
名称Name类型Type说明Description
elementStringelement(类型 `String`)。The element.
refString引用(类型 `String`)。The ref.
textString文本(类型 `String`)。The text.
submitBoolean提交(类型 `Boolean`)。The submit.
slowlyBooleanslowly(类型 `Boolean`)。The slowly.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:104–112

takeScreenshot

public String takeScreenshot()

返回 takeScreenshot 结果。

Returns the take screenshot.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:114–116

takeScreenshot

public String takeScreenshot(Boolean raw, String filename, String element, String ref)

执行 takeScreenshot 方法。

Performs the take screenshot operation.

参数Parameters
名称Name类型Type说明Description
rawBoolean原始(类型 `Boolean`)。The raw.
filenameStringfilename(类型 `String`)。The filename.
elementStringelement(类型 `String`)。The element.
refString引用(类型 `String`)。The ref.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:118–125

snapshot

public String snapshot()

返回快照。

Returns the snapshot.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:127–129

tabNew

public String tabNew(String url)

设置该参数。

Performs the tab new operation.

参数Parameters
名称Name类型Type说明Description
urlString服务地址(类型 `String`)。The url.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:131–135

tabSelect

public String tabSelect(Integer index)

设置该参数。

Performs the tab select operation.

参数Parameters
名称Name类型Type说明Description
indexInteger索引(类型 `Integer`)。The index.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:137–141

tabClose

public String tabClose(Integer index)

设置该参数。

Performs the tab close operation.

参数Parameters
名称Name类型Type说明Description
indexInteger索引(类型 `Integer`)。The index.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:143–147

tabList

public String tabList()

返回 tabList 结果。

Returns the tab list.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:149–151

waitFor

public String waitFor(Double time)

等待用于。

Performs the wait for operation.

参数Parameters
名称Name类型Type说明Description
timeDouble时间(类型 `Double`)。The time.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:153–155

waitFor

public String waitFor(Double time, String text, String textGone)

等待用于。

Performs the wait for operation.

参数Parameters
名称Name类型Type说明Description
timeDouble时间(类型 `Double`)。The time.
textString文本(类型 `String`)。The text.
textGoneString文本 Gone(类型 `String`)。The text gone.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:157–163

resize

public String resize(Double width, Double height)

执行 resize 方法。

Performs the resize operation.

参数Parameters
名称Name类型Type说明Description
widthDoublewidth(类型 `Double`)。The width.
heightDoubleheight(类型 `Double`)。The height.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:165–170

closeBrowser

public String closeBrowser()

关闭 closeBrowser。

Closes the browser.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:172–174

consoleMessages

public String consoleMessages()

返回控制台消息。

Returns the console messages.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:176–178

networkRequests

public String networkRequests()

返回 networkRequests 结果。

Returns the network requests.

返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:180–182

hover

public String hover(String element, String ref)

执行 hover 方法。

Performs the hover operation.

参数Parameters
名称Name类型Type说明Description
elementStringelement(类型 `String`)。The element.
refString引用(类型 `String`)。The ref.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:192–197

pressKey

public String pressKey(String key)

设置该参数。

Performs the press key operation.

参数Parameters
名称Name类型Type说明Description
keyString键(类型 `String`)。The key.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:199–203

handleDialog

public String handleDialog(Boolean accept, String promptText)

处理 handleDialog。

Performs the handle dialog operation.

参数Parameters
名称Name类型Type说明Description
acceptBooleanaccept(类型 `Boolean`)。The accept.
promptTextString提示词文本(类型 `String`)。The prompt text.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:205–212

fileUpload

public String fileUpload(String[] paths)

设置文件上传。

Performs the file upload operation.

参数Parameters
名称Name类型Type说明Description
pathsString[]paths(类型 `String[]`)。The paths.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:214–218

pdfSave

public String pdfSave(String filename)

设置该参数。

Performs the pdf save operation.

参数Parameters
名称Name类型Type说明Description
filenameStringfilename(类型 `String`)。The filename.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:220–226

drag

public String drag(String startElement, String startRef, String endElement, String endRef)

执行 drag 方法。

Performs the drag operation.

参数Parameters
名称Name类型Type说明Description
startElementString启动 Element(类型 `String`)。The start element.
startRefString启动引用(类型 `String`)。The start ref.
endElementString结束 Element(类型 `String`)。The end element.
endRefString结束引用(类型 `String`)。The end ref.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:228–235

selectOption

public String selectOption(String element, String ref, String[] values)

执行选择选项相关操作。

Performs the select option operation.

参数Parameters
名称Name类型Type说明Description
elementStringelement(类型 `String`)。The element.
refString引用(类型 `String`)。The ref.
valuesString[]值(类型 `String[]`)。The values.
返回Returns String
返回字符串结果。Returns a string.
源码Source io/agentscope/runtime/sandbox/box/BrowserSandbox.java:237–243

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.