From 40059fdd67049a7bb254291776f680e19ffa706d Mon Sep 17 00:00:00 2001 From: xuehuitian45 <13069167198@163.com> Date: Mon, 22 Dec 2025 10:07:01 +0800 Subject: [PATCH] fix(sandbox): add directly rw bind file support in docker mode --- .../sandbox/manager/SandboxManager.java | 21 +++++++++++++++++++ .../manager/model/fs/FileSystemConfig.java | 15 ++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxManager.java b/core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxManager.java index 602838ba..0c71f8d1 100644 --- a/core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxManager.java +++ b/core/src/main/java/io/agentscope/runtime/sandbox/manager/SandboxManager.java @@ -519,6 +519,27 @@ public ContainerModel createContainer(SandboxType sandboxType, String mountDir, logger.info("Added readonly mount: " + hostPath + " -> " + containerPath); } } + Map nonCopyMounts = managerConfig.getFileSystemConfig().getNonCopyMount(); + if(nonCopyMounts != null && !nonCopyMounts.isEmpty()){ + logger.info("Adding non-copy mounts: " + nonCopyMounts.size() + " mount(s)"); + for (Map.Entry entry : nonCopyMounts.entrySet()) { + String hostPath = entry.getKey(); + String containerPath = entry.getValue(); + if (!java.nio.file.Paths.get(hostPath).isAbsolute()) { + hostPath = java.nio.file.Paths.get(hostPath).toAbsolutePath().toString(); + logger.info("Converting relative path to absolute: " + hostPath); + } + java.io.File hostFile = new java.io.File(hostPath); + if (!hostFile.exists()) { + logger.warning("NonCopy mount host path does not exist: " + hostPath + ", skipping"); + continue; + } + volumeBindings.add(new VolumeBinding(hostPath, containerPath, "rw")); + logger.info("Added non Copy mount: " + hostPath + " -> " + containerPath); + } + } + + Map runtimeConfig = Map.of(); if (sandboxConfig != null) { runtimeConfig = sandboxConfig.getRuntimeConfig(); diff --git a/core/src/main/java/io/agentscope/runtime/sandbox/manager/model/fs/FileSystemConfig.java b/core/src/main/java/io/agentscope/runtime/sandbox/manager/model/fs/FileSystemConfig.java index 99da0626..ff2eb04d 100644 --- a/core/src/main/java/io/agentscope/runtime/sandbox/manager/model/fs/FileSystemConfig.java +++ b/core/src/main/java/io/agentscope/runtime/sandbox/manager/model/fs/FileSystemConfig.java @@ -23,6 +23,7 @@ public class FileSystemConfig { private Map readonlyMounts; private String storageFolderPath; private String mountDir; + private Map nonCopyMount; protected FileSystemConfig(FileSystemType fileSystemType) { this.fileSystemType = fileSystemType; @@ -33,6 +34,7 @@ protected FileSystemConfig(Builder builder) { this.readonlyMounts = builder.readonlyMounts; this.storageFolderPath = builder.storageFolderPath; this.mountDir = builder.mountDir; + this.nonCopyMount = builder.nonCopyMounts; } public FileSystemType getFileSystemType() { @@ -51,13 +53,16 @@ public String getMountDir() { return mountDir; } + public Map getNonCopyMount() { + return nonCopyMount; + } public static abstract class Builder> { protected FileSystemType fileSystemType; protected Map readonlyMounts; protected String storageFolderPath = ""; protected String mountDir = "sessions_mount_dir"; - + protected Map nonCopyMounts; protected Builder(FileSystemType fileSystemType) { this.fileSystemType = fileSystemType; @@ -78,6 +83,14 @@ public T addReadonlyMount(String hostPath, String containerPath) { return self(); } + public T addNonCopyMount(String hostPath, String containerPath) { + if (this.nonCopyMounts == null) { + this.nonCopyMounts = new HashMap<>(); + } + this.nonCopyMounts.put(hostPath, containerPath); + return self(); + } + public T storageFolderPath(String storageFolderPath) { this.storageFolderPath = storageFolderPath; return self();