Class: Hermetic::Backends::Hosted::E2B

Inherits:
Base
  • Object
show all
Defined in:
lib/hermetic/backends/hosted/e2b.rb

Overview

E2B (e2b.dev) — a vendor microVM per run. trust :vendor, off-host by construction: a guest escape lands in E2B's cloud, not next to the app's secrets.

BEST-EFFORT WIRE SHAPE (spec §6.4): BASE_URL, the endpoint path, and the request/response bodies below are a design-time approximation of E2B's create-and-run API. Pin them against the live API via the :hosted smoke layer (spec §5) before first real use.

Constant Summary collapse

BASE_URL =
"https://api.e2b.dev"

Constants inherited from Base

Base::OFF_HOST_TRUST, Base::TIMEOUT_EXIT

Instance Attribute Summary

Attributes inherited from Base

#limits, #trust

Instance Method Summary collapse

Methods inherited from Base

#enabled?, #off_host?, #run

Methods included from SilasLedgerGuard

#run

Constructor Details

#initialize(api_key:, template: "base", base_url: BASE_URL, transport: nil, **opts) ⇒ E2B

Returns a new instance of E2B.

Raises:



17
18
19
20
21
22
23
24
25
# File 'lib/hermetic/backends/hosted/e2b.rb', line 17

def initialize(api_key:, template: "base", base_url: BASE_URL, transport: nil, **opts)
  raise ConfigError, "api_key is required for Hosted::E2B" if api_key.to_s.strip.empty?

  super(trust: :vendor, **opts)
  @api_key = api_key
  @template = template
  @base_url = base_url.to_s.chomp("/")
  @transport = transport || Transport::Http.new
end

Instance Method Details

#backend_nameObject



27
# File 'lib/hermetic/backends/hosted/e2b.rb', line 27

def backend_name = :e2b

#create_and_run_spec(request) ⇒ Object

Pure: one run as an HTTP request spec — unit-testable with zero infra. Box credentials are already resolved into clean_env (:env mode), so the model-visible command never carries a raw token.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/hermetic/backends/hosted/e2b.rb', line 32

def create_and_run_spec(request)
  {
    method: :post,
    url: "#{@base_url}/v1/sandboxes/exec",
    headers: {
      "X-API-Key" => @api_key,
      "Content-Type" => "application/json",
      "Idempotency-Key" => request.idempotency_key
    },
    body: JSON.generate(
      template: @template,
      command: request.exec_string,
      stdin: request.stdin,
      files: request.files,
      env: request.clean_env,
      network: { egress: request.network.egress },
      timeout: request.timeout,
      limits: request.limits.to_h
    )
  }
end