Module: E2B

Defined in:
lib/e2b.rb,
lib/e2b/client.rb,
lib/e2b/errors.rb,
lib/e2b/sandbox.rb,
lib/e2b/version.rb,
lib/e2b/template.rb,
lib/e2b/paginator.rb,
lib/e2b/ready_cmd.rb,
lib/e2b/services/git.rb,
lib/e2b/services/pty.rb,
lib/e2b/configuration.rb,
lib/e2b/api/http_client.rb,
lib/e2b/sandbox_helpers.rb,
lib/e2b/template_logger.rb,
lib/e2b/dockerfile_parser.rb,
lib/e2b/models/build_info.rb,
lib/e2b/models/entry_info.rb,
lib/e2b/services/commands.rb,
lib/e2b/models/sandbox_info.rb,
lib/e2b/models/template_tag.rb,
lib/e2b/services/filesystem.rb,
lib/e2b/models/snapshot_info.rb,
lib/e2b/models/process_result.rb,
lib/e2b/services/base_service.rb,
lib/e2b/services/watch_handle.rb,
lib/e2b/services/command_handle.rb,
lib/e2b/models/template_tag_info.rb,
lib/e2b/services/live_streamable.rb,
lib/e2b/models/template_log_entry.rb,
lib/e2b/models/build_status_reason.rb,
lib/e2b/models/template_build_status_response.rb

Overview

E2B SDK for Ruby

Provides access to E2B sandboxes - secure cloud environments for AI-generated code execution.

Examples:

Quick start with Sandbox class (recommended)

sandbox = E2B::Sandbox.create(template: "base", api_key: "your-key")

result = sandbox.commands.run("echo 'Hello, World!'")
puts result.stdout

sandbox.files.write("/home/user/hello.txt", "Hello!")
content = sandbox.files.read("/home/user/hello.txt")

sandbox.kill

Using Client class

client = E2B::Client.new(api_key: "your-api-key")
sandbox = client.create(template: "base")

Using global configuration

E2B.configure do |config|
  config.api_key = "your-api-key"
end

sandbox = E2B::Sandbox.create(template: "base")

See Also:

Defined Under Namespace

Modules: API, DockerfileParser, Models, SandboxHelpers, Services Classes: AuthenticationError, BasePaginator, BuildError, Client, CommandExitError, Configuration, ConfigurationError, ConflictError, DefaultBuildLogger, E2BError, FileUploadError, GitAuthError, GitUpstreamError, InvalidArgumentError, NotEnoughSpaceError, NotFoundError, RateLimitError, ReadyCmd, Sandbox, SandboxPaginator, SandboxStateError, SnapshotPaginator, Template, TemplateError, TimeoutError

Constant Summary collapse

ALL_TRAFFIC =
"0.0.0.0/0"
SandboxError =

Alias matching official SDK naming

E2BError
VERSION =
"0.3.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationConfiguration?

Returns Global configuration.

Returns:



79
80
81
# File 'lib/e2b.rb', line 79

def configuration
  @configuration
end

Class Method Details

.configure {|config| ... } ⇒ Configuration

Configure the E2B SDK globally

Examples:

E2B.configure do |config|
  config.api_key = "your-api-key"
  config.domain = "e2b.app"
end

Yields:

  • (config)

    Configuration block

Yield Parameters:

Returns:



92
93
94
95
96
# File 'lib/e2b.rb', line 92

def configure
  self.configuration ||= Configuration.new
  yield(configuration) if block_given?
  configuration
end

.default_build_logger(min_level: nil, io: $stdout) ⇒ Object



47
48
49
50
# File 'lib/e2b/template_logger.rb', line 47

def default_build_logger(min_level: nil, io: $stdout)
  build_logger = DefaultBuildLogger.new(min_level: min_level, io: io)
  build_logger.method(:logger).to_proc
end

.reset_configuration!Object

Reset global configuration



99
100
101
# File 'lib/e2b.rb', line 99

def reset_configuration!
  self.configuration = nil
end

.wait_for_file(filename) ⇒ Object



27
28
29
# File 'lib/e2b/ready_cmd.rb', line 27

def wait_for_file(filename)
  ReadyCmd.new("[ -f #{filename} ]")
end

.wait_for_port(port) ⇒ Object



15
16
17
# File 'lib/e2b/ready_cmd.rb', line 15

def wait_for_port(port)
  ReadyCmd.new("ss -tuln | grep :#{port}")
end

.wait_for_process(process_name) ⇒ Object



23
24
25
# File 'lib/e2b/ready_cmd.rb', line 23

def wait_for_process(process_name)
  ReadyCmd.new("pgrep #{process_name} > /dev/null")
end

.wait_for_timeout(timeout) ⇒ Object



31
32
33
34
# File 'lib/e2b/ready_cmd.rb', line 31

def wait_for_timeout(timeout)
  seconds = [1, timeout.to_i / 1000].max
  ReadyCmd.new("sleep #{seconds}")
end

.wait_for_url(url, status_code = 200) ⇒ Object



19
20
21
# File 'lib/e2b/ready_cmd.rb', line 19

def wait_for_url(url, status_code = 200)
  ReadyCmd.new(%(curl -s -o /dev/null -w "%{http_code}" #{url} | grep -q "#{status_code}"))
end