Class SandboxedExecution

java.lang.Object
com.tnsai.coordination.supervisor.SandboxedExecution

public final class SandboxedExecution extends Object
Runs agent actions in a sandboxed context with resource limits.

SandboxedExecution provides a way to execute agent tasks with constraints such as timeouts and action allow-lists. This prevents runaway agents from consuming excessive resources or performing unauthorized operations.

Usage Example


 SandboxConfig config = new SandboxConfig(
     Duration.ofSeconds(30),  // timeout
     64 * 1024 * 1024,        // 64MB memory limit
     Set.of("search", "read"),  // allowed actions
     true                     // read-only
 );

 SandboxResult result = SandboxedExecution.execute(agent, "Analyze this data", config);
 if (result.completed()) {
     System.out.println(result.result());
 }
 
  • Method Details

    • execute

      public static SandboxedExecution.SandboxResult execute(com.tnsai.agents.Agent agent, String task, SandboxedExecution.SandboxConfig config)
      Executes an agent task in a sandboxed context.

      The task is run in a separate thread with the configured timeout. If the timeout is exceeded, the execution is interrupted and a failed result is returned.

      Parameters:
      agent - the agent to execute the task
      task - the task prompt to send to the agent
      config - sandbox configuration
      Returns:
      result of the execution
      Throws:
      NullPointerException - if any argument is null