Package com.atlassian.confluence.util.sandbox

Sandbox framework enables running any java code independent of Confluence core in a separate OS process which can crash, run out of memory, be killed and restarted without affecting Confluence.

Confluence provides the sandbox registry that can be imported and then used by a plugin to obtain a sandbox for running unsafe code. E.g.


     SandboxSpec spec = SandboxSpec.builder()
          .withMinimumMemoryInMb(512)
          .build(Duration.ofSeconds(30));
     Sandbox sandbox = sandboxRegistry.get(spec);
 

The obtained sandbox object then can be used for running different sandbox tasks.


     SandboxTask<String, String> task = new ReverseStringTask();
     sandbox.execute(task, "hello world");
 

Each instance of a sandbox is a java process with substantial amount of memory. There's a limited number of sandbox processes and they might be shared between Confluence core and plugins. For this reason, sandbox tasks should be created with as little time limit, as possible.