Class E2BSandboxTools

java.lang.Object
com.tnsai.tools.code.E2BSandboxTools

public class E2BSandboxTools extends Object
Function-shape E2B (e2b.dev) cloud sandbox tools — secure isolated containers for running untrusted code. Replaces the legacy E2BSandboxTool which fronted seven operations behind one JSON-dispatch tool.

Each operation now has its own typed @Tool method — much friendlier for LLM tool-calling than picking a string out of a "operation" field.

MethodHTTPIdempotent
e2bCreate(java.lang.String)POST /sandboxesfalse (creates a resource)
e2bExecute(java.lang.String, java.lang.String, java.lang.String, int)POST /sandboxes/{id}/processesfalse (runs user code)
e2bUpload(java.lang.String, java.lang.String, java.lang.String)POST /sandboxes/{id}/filesfalse (writes a file)
e2bDownload(java.lang.String, java.lang.String)GET /sandboxes/{id}/filestrue (read-only)
e2bInstall(java.lang.String, java.util.List<java.lang.String>, java.lang.String)POST /processes (pip/npm install)false (mutates env)
e2bList()GET /sandboxestrue (read-only)
e2bKill(java.lang.String)DELETE /sandboxes/{id}false (destroys a resource)

Requires E2B_API_KEY. Sign up at e2b.dev/dashboard (free tier: 100 hours/month).

Since:
0.5.7 (Phase 2 batch 12c — built-in tool migration to function shape, see #188)
  • Constructor Details

    • E2BSandboxTools

      public E2BSandboxTools()
      Default constructor — picks E2B_API_KEY from env.
    • E2BSandboxTools

      public E2BSandboxTools(String apiKey)
      Explicit-key constructor.
    • E2BSandboxTools

      public E2BSandboxTools(String apiKey, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper)
      Full constructor for tests / shared HTTP.
  • Method Details

    • e2bCreate

      @Tool(name="e2b_create", description="Create a new E2B sandbox (isolated cloud container). {template} picks the base image: \"base\" (minimal Linux), \"python\" (Python 3.11 + common pkgs), \"nodejs\" (Node.js 20 + npm), or any custom-template id. Returns the new sandboxId \u2014 pass it to e2b_execute / e2b_upload / etc.", keywords={"e2b","sandbox","create","container"}, idempotent=false) public String e2bCreate(@ToolParam(description="Sandbox template id (\"base\", \"python\", \"nodejs\", or custom)",required=false,defaultValue="base") String template) throws IOException
      Throws:
      IOException
    • e2bExecute

      @Tool(name="e2b_execute", description="Execute code inside an existing E2B sandbox. {sandboxId} comes from e2b_create. {language} is \"python\" (default), \"javascript\"/\"nodejs\", or \"bash\"/\"shell\". {timeoutSeconds} is per-process (default 30, max 600). Returns the JSON response from E2B with stdout/stderr/exitCode fields.", keywords={"e2b","sandbox","execute","run","code"}, idempotent=false) public String e2bExecute(@ToolParam(description="Sandbox id from e2b_create") String sandboxId, @ToolParam(description="Code to execute") String code, @ToolParam(description="Language: python / javascript / nodejs / bash / shell",required=false,defaultValue="python") String language, @ToolParam(description="Process timeout in seconds (default 30, capped at 600)",required=false,defaultValue="30") int timeoutSeconds) throws IOException
      Throws:
      IOException
    • e2bUpload

      @Tool(name="e2b_upload", description="Upload a small file (text content) to an E2B sandbox. {filename} is the absolute path inside the sandbox (e.g. \"/home/user/data.csv\"). Returns the JSON response from E2B confirming the write.", keywords={"e2b","sandbox","upload","file","write"}, idempotent=false) public String e2bUpload(@ToolParam(description="Sandbox id from e2b_create") String sandboxId, @ToolParam(description="Absolute path inside the sandbox") String filename, @ToolParam(description="File content (text)") String content) throws IOException
      Throws:
      IOException
    • e2bDownload

      @Tool(name="e2b_download", description="Download the text content of a file from an E2B sandbox. {filename} is the absolute path inside the sandbox. Returns the file\'s text content.", keywords={"e2b","sandbox","download","file","read"}, idempotent=true) public String e2bDownload(@ToolParam(description="Sandbox id from e2b_create") String sandboxId, @ToolParam(description="Absolute path inside the sandbox") String filename) throws IOException
      Throws:
      IOException
    • e2bInstall

      @Tool(name="e2b_install", description="Install packages inside an E2B sandbox. {packages} is a list of package names. Picks the package manager from {language}: \"javascript\"/\"nodejs\" \u2192 npm, anything else \u2192 pip. Returns the install command\'s output. Uses a 120-second timeout (installs can be slow).", keywords={"e2b","sandbox","install","pip","npm","packages"}, idempotent=false) public String e2bInstall(@ToolParam(description="Sandbox id from e2b_create") String sandboxId, @ToolParam(description="Packages to install") List<String> packages, @ToolParam(description="Language: \"python\" (pip) or \"javascript\"/\"nodejs\" (npm)",required=false,defaultValue="python") String language) throws IOException
      Throws:
      IOException
    • e2bList

      @Tool(name="e2b_list", description="List all currently-running E2B sandboxes for this account. Returns the JSON array of sandbox metadata (id, template, started-at, \u2026). Useful for inventory / cleanup before creating new ones.", keywords={"e2b","sandbox","list","inventory"}, idempotent=true) public String e2bList() throws IOException
      Throws:
      IOException
    • e2bKill

      @Tool(name="e2b_kill", description="Terminate an E2B sandbox immediately. Idempotent at the API level \u2014 killing an already-killed sandbox returns 404, which this tool treats as success. Returns the literal string \"killed\" on success.", keywords={"e2b","sandbox","kill","terminate","delete"}, idempotent=false) public String e2bKill(@ToolParam(description="Sandbox id from e2b_create") String sandboxId) throws IOException
      Throws:
      IOException