From 26dc4a1aec5e00676658e5c3c84b50996d79e76b Mon Sep 17 00:00:00 2001 From: artboy <80608452+itxaiohanglover@users.noreply.github.com> Date: Tue, 23 Jun 2026 14:46:16 +0800 Subject: [PATCH] fix(sandbox): serialize only sandboxId to prevent Jackson circular dependency writeValueAsString(sandbox) triggers getDesktopUrl() which calls managerApi.getInfo(sandbox) in remote mode, causing infinite recursion and StackOverflowError. Fix: serialize only sandboxId (same as local mode) instead of the full Sandbox object. The remote API only needs the sandbox ID for container lookups. Fixes #105 --- .../runtime/sandbox/manager/SandboxService.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sandbox-core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxService.java b/sandbox-core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxService.java index 7ef3dec..bf49426 100644 --- a/sandbox-core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxService.java +++ b/sandbox-core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxService.java @@ -150,7 +150,7 @@ public ContainerModel createContainer(Sandbox sandbox) throws JsonProcessingExce if (this.remoteHttpClient != null) { logger.info("Creating container in remote mode via RemoteHttpClient"); ObjectMapper mapper = new ObjectMapper(); - String sandboxJson = mapper.writeValueAsString(sandbox); + String sandboxJson = mapper.writeValueAsString(Map.of("sandboxId", sandbox.getSandboxId())); Map request = Map.of("sandbox", sandboxJson); Object result = remoteHttpClient.makeRequest( RequestMethod.POST, @@ -536,7 +536,7 @@ public ContainerModel getInfo(Sandbox sandbox) throws JsonProcessingException { if (this.remoteHttpClient != null) { logger.info("Getting sandbox info in remote mode via RemoteHttpClient"); ObjectMapper mapper = new ObjectMapper(); - String sandboxJson = mapper.writeValueAsString(sandbox); + String sandboxJson = mapper.writeValueAsString(Map.of("sandboxId", sandbox.getSandboxId())); Map request = Map.of("sandbox", sandboxJson); Object result = remoteHttpClient.makeRequest( RequestMethod.POST, @@ -599,7 +599,7 @@ public Map listTools(Sandbox sandbox, String toolType) throws Js if (this.remoteHttpClient != null) { logger.info("Listing tools in remote mode via RemoteHttpClient"); ObjectMapper mapper = new ObjectMapper(); - String sandboxJson = mapper.writeValueAsString(sandbox); + String sandboxJson = mapper.writeValueAsString(Map.of("sandboxId", sandbox.getSandboxId())); Map request = Map.of( "sandbox", sandboxJson, "toolType", toolType @@ -630,7 +630,7 @@ public String callTool(Sandbox sandbox, String toolName, Map arg if (this.remoteHttpClient != null) { logger.info("Calling tool in remote mode via RemoteHttpClient"); ObjectMapper mapper = new ObjectMapper(); - String sandboxJson = mapper.writeValueAsString(sandbox); + String sandboxJson = mapper.writeValueAsString(Map.of("sandboxId", sandbox.getSandboxId())); Map request = Map.of( "sandbox", sandboxJson, "toolName", toolName, @@ -660,7 +660,7 @@ public Map addMcpServers(Sandbox sandbox, Map se if (this.remoteHttpClient != null) { logger.info("Adding MCP servers in remote mode via RemoteHttpClient"); ObjectMapper mapper = new ObjectMapper(); - String sandboxJson = mapper.writeValueAsString(sandbox); + String sandboxJson = mapper.writeValueAsString(Map.of("sandboxId", sandbox.getSandboxId())); Map request = Map.of( "sandbox", sandboxJson, "serverConfigs", serverConfigs,