Class LocalFilesystemWithShell

java.lang.Object
io.agentscope.harness.agent.filesystem.local.LocalFilesystem
io.agentscope.harness.agent.filesystem.local.LocalFilesystemWithShell
All Implemented Interfaces:
AbstractFilesystem, AbstractSandboxFilesystem

public class LocalFilesystemWithShell extends LocalFilesystem implements AbstractSandboxFilesystem
Filesystem with unrestricted local shell command execution.

This implementation extends LocalFilesystem to add shell command execution capabilities. Commands are executed directly on the host system without any sandboxing, process isolation, or security restrictions.

WARNING: This implementation grants agents BOTH direct filesystem access AND unrestricted shell execution on your local machine. Use with extreme caution and only in appropriate environments (local dev, CI/CD with proper secret management).

  • Field Details

    • DEFAULT_EXECUTE_TIMEOUT

      public static final int DEFAULT_EXECUTE_TIMEOUT
      Default timeout in seconds for shell command execution.
      See Also:
  • Constructor Details

    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(Path rootDir)
      Creates an abstract filesystem with default settings.
      Parameters:
      rootDir - working directory for both filesystem and shell operations
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(String rootDir)
      Same as LocalFilesystemWithShell(Path) with a path string; see LocalFilesystem(String) for null / blank rules.
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(Path rootDir, NamespaceFactory namespaceFactory)
      Creates an abstract filesystem with default settings and namespace support.
      Parameters:
      rootDir - working directory for both filesystem and shell operations
      namespaceFactory - optional namespace factory for path scoping (null for none)
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(String rootDir, NamespaceFactory namespaceFactory)
      Same as LocalFilesystemWithShell(Path, NamespaceFactory) with a path string; see LocalFilesystem(String) for null / blank rules.
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(Path rootDir, boolean virtualMode, int timeout, int maxOutputBytes, Map<String,String> env, boolean inheritEnv)
      Creates a abstract filesystem with full configuration.
      Parameters:
      rootDir - working directory for both filesystem and shell operations
      virtualMode - enable virtual path mode for filesystem operations
      timeout - default maximum time in seconds for shell command execution
      maxOutputBytes - maximum number of bytes to capture from command output
      env - environment variables for shell commands (null for empty)
      inheritEnv - whether to inherit the parent process's environment variables
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(String rootDir, boolean virtualMode, int timeout, int maxOutputBytes, Map<String,String> env, boolean inheritEnv)
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(Path rootDir, boolean virtualMode, int timeout, int maxOutputBytes, Map<String,String> env, boolean inheritEnv, NamespaceFactory namespaceFactory)
      Creates a abstract filesystem with full configuration and namespace support.
      Parameters:
      rootDir - working directory for both filesystem and shell operations
      virtualMode - enable virtual path mode for filesystem operations
      timeout - default maximum time in seconds for shell command execution
      maxOutputBytes - maximum number of bytes to capture from command output
      env - environment variables for shell commands (null for empty)
      inheritEnv - whether to inherit the parent process's environment variables
      namespaceFactory - optional namespace factory for path scoping (null for none)
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(Path rootDir, boolean virtualMode, int timeout, int maxOutputBytes, Map<String,String> env, boolean inheritEnv, NamespaceFactory namespaceFactory, Path shellCwd)
      Creates a abstract filesystem with full configuration, namespace support, and a custom shell working directory.
      Parameters:
      rootDir - working directory for filesystem operations (read/write/edit/glob/...)
      virtualMode - enable virtual path mode for filesystem operations
      timeout - default maximum time in seconds for shell command execution
      maxOutputBytes - maximum number of bytes to capture from command output
      env - environment variables for shell commands (null for empty)
      inheritEnv - whether to inherit the parent process's environment variables
      namespaceFactory - optional namespace factory for path scoping (null for none)
      shellCwd - working directory for shell command execution; when null, falls back to rootDir (with namespace prefix when configured)
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(Path rootDir, LocalFsMode mode, PathPolicy pathPolicy, int timeout, int maxOutputBytes, Map<String,String> env, boolean inheritEnv, NamespaceFactory namespaceFactory, Path shellCwd)
      Most-complete constructor: filesystem operations follow mode and pathPolicy (see LocalFilesystem(Path, LocalFsMode, PathPolicy, int, NamespaceFactory)); shell commands run with pwd = shellCwd when set, otherwise the filesystem root.
      Parameters:
      rootDir - filesystem root for relative-path operations
      mode - path-resolution policy (null treated as LocalFsMode.UNRESTRICTED)
      pathPolicy - allow-list for LocalFsMode.ROOTED; ignored otherwise
      timeout - default shell timeout (seconds, must be positive)
      maxOutputBytes - byte cap for captured shell output
      env - environment variables for shell commands (null for empty)
      inheritEnv - whether to inherit the parent process environment
      namespaceFactory - optional per-user/session namespace factory
      shellCwd - shell pwd; null falls back to rootDir (with namespace prefix when configured)
    • LocalFilesystemWithShell

      public LocalFilesystemWithShell(String rootDir, boolean virtualMode, int timeout, int maxOutputBytes, Map<String,String> env, boolean inheritEnv, NamespaceFactory namespaceFactory)
  • Method Details

    • id

      public String id()
      Description copied from interface: AbstractSandboxFilesystem
      Unique identifier for this filesystem/sandbox instance.
      Specified by:
      id in interface AbstractSandboxFilesystem
      Returns:
      id string
    • getShellCwd

      public Path getShellCwd()
      Returns the working directory configured for shell execute() calls, or null when shell falls back to the filesystem root (with namespace prefix). Used by upstream code that needs to expose the user-visible project directory in prompts or diagnostics.
    • execute

      public ExecuteResponse execute(io.agentscope.core.agent.RuntimeContext runtimeContext, String command, Integer timeoutSeconds)
      Description copied from interface: AbstractSandboxFilesystem
      Execute a shell command in the environment backing this filesystem.
      Specified by:
      execute in interface AbstractSandboxFilesystem
      Parameters:
      runtimeContext - per-call agent context; may be null when unavailable
      command - full shell command string to execute
      timeoutSeconds - maximum time in seconds to wait for the command to complete; null uses the filesystem's default timeout
      Returns:
      ExecuteResponse with combined output, exit code, and truncation flag; a non-successful response (see ExecuteResponse.isSuccess()) means the command did not complete successfully, so output must not be parsed as normal command output