Skip to content

reactAgent 使用远程沙箱问题,求指导 #107

Description

@Renwukun

reactAgent 使用远程沙箱问题。

  • 使用远程沙箱写执行写文件操作,报错!
  • 我的docker服务没有开启2375端口,生产环境因为安全原因也不会开放这个端口!

第一步,使用runtime-sandbox-server启动沙箱服务,服务正常。

runtime-sandbox-server

INFO:     Started server process [19265]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO /Users/xxx/miniforge3/envs/python3.11/lib/python3.11/site-packages/agentscope_runtime/sandbox/manager/sandbox_manager.py:464 | 2026-06-04 10:54:32 | Watcher started, interval=1s
INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     127.0.0.1:60843 - "GET /health HTTP/1.1" 200 OK

第二步,创建 reactAgent并使用沙箱

	@BeforeAll
		static void setUp() {
			
			  。。。。。。
	                 // 不指定远程沙箱是可行的。docker ps也是可以正常看到创建的沙箱容器。
			// ManagerConfig managerConfig = ManagerConfig.builder().build();

			// 指定远程沙箱报错!是什么原因?
			ManagerConfig managerConfig = ManagerConfig.builder().baseUrl("http://127.0.0.1:8000").build();

		
			sandboxService = new SandboxService(managerConfig);
			sandboxService.start();
	}

    @Test
	public void testFsSandboxTools() throws Exception {
		FilesystemSandbox sandbox = new FilesystemSandbox(sandboxService, "testUser", "testSession");

		ReactAgent fsSandboxToolAgent = ReactAgent.builder()
			.name("tool_test_agent")
			.model(chatModel)
			.chatOptions(chatOptions)
			.description("An agent that can use tools to answer questions.")
			.instruction("You are a intelligent agent that can use tools to perform tasks.")
			.tools(List.of(ToolkitInit.WriteFileTool(sandbox)))
			.build();

		     。。。。。。
}

报错信息如下

11:15:25.461 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Initialized SandboxService in remote mode with base URL: http://127.0.0.1:8080
11:15:25.463 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Initializing SandboxService with container manager: DOCKER
11:15:25.463 [main] INFO io.agentscope.runtime.sandbox.manager.utils.PortManager -- PortManager initialized with port range: 49152-59152
11:15:25.466 [main] INFO io.agentscope.runtime.sandbox.manager.client.container.docker.DockerClient -- Connecting to Docker at tcp://localhost:2375 without TLS
11:15:25.600 [main] WARN io.agentscope.runtime.sandbox.manager.client.container.docker.DockerClient -- Failed to connect to Docker using configured host (localhost:2375): com.github.dockerjava.zerodep.shaded.org.apache.hc.client5.http.HttpHostConnectException: Connect to http://localhost:2375 failed: Connection refused
11:15:25.600 [main] INFO io.agentscope.runtime.sandbox.manager.client.container.docker.DockerClient -- Falling back to default Docker configuration
11:15:25.666 [main] INFO io.agentscope.runtime.sandbox.manager.client.container.docker.DockerClientStarter -- Docker client created
11:15:25.666 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- SandboxService started.
11:15:28.759 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Creating container in remote mode via RemoteHttpClient
11:15:28.763 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Getting sandbox info in remote mode via RemoteHttpClient
11:15:28.763 [main] ERROR io.agentscope.runtime.sandbox.box.Sandbox -- Failed to initialize sandbox: Sandbox null is not healthy: null (through reference chain: io.agentscope.runtime.sandbox.box.FilesystemSandbox["desktopUrl"])
11:15:28.763 [main] ERROR io.agentscope.runtime.sandbox.tools.fs.WriteFileTool -- Write File Error: Failed to initialize sandbox
11:15:31.391 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Creating container in remote mode via RemoteHttpClient
11:15:31.392 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Getting sandbox info in remote mode via RemoteHttpClient
11:15:31.393 [main] ERROR io.agentscope.runtime.sandbox.box.Sandbox -- Failed to initialize sandbox: Sandbox null is not healthy: null (through reference chain: io.agentscope.runtime.sandbox.box.FilesystemSandbox["desktopUrl"])
11:15:31.393 [main] ERROR io.agentscope.runtime.sandbox.tools.fs.WriteFileTool -- Write File Error: Failed to initialize sandbox
11:15:34.306 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Creating container in remote mode via RemoteHttpClient
11:15:34.307 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Getting sandbox info in remote mode via RemoteHttpClient
11:15:34.307 [main] ERROR io.agentscope.runtime.sandbox.box.Sandbox -- Failed to initialize sandbox: Sandbox null is not healthy: null (through reference chain: io.agentscope.runtime.sandbox.box.FilesystemSandbox["desktopUrl"])
11:15:34.307 [main] ERROR io.agentscope.runtime.sandbox.tools.fs.WriteFileTool -- Write File Error: Failed to initialize sandbox
11:15:38.245 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Creating container in remote mode via RemoteHttpClient
11:15:38.246 [main] INFO io.agentscope.runtime.sandbox.manager.SandboxService -- Getting sandbox info in remote mode via RemoteHttpClient
11:15:38.246 [main] ERROR io.agentscope.runtime.sandbox.box.Sandbox -- Failed to initialize sandbox: Sandbox null is not healthy: null (through reference chain: io.agentscope.runtime.sandbox.box.FilesystemSandbox["desktopUrl"])
11:15:38.246 [main] ERROR io.agentscope.runtime.sandbox.tools.fs.WriteFileTool -- Write File Error: Failed to initialize sandbox
=== Write File Sandbox Agent Tool Test ===

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions