Module: OpenSandbox

Defined in:
lib/open_sandbox/client.rb,
lib/open_sandbox/pools.rb,
lib/open_sandbox/errors.rb,
lib/open_sandbox/models.rb,
lib/open_sandbox/runner.rb,
lib/open_sandbox/version.rb,
lib/open_sandbox/sandboxes.rb,
lib/open_sandbox/http_client.rb,
lib/generators/open_sandbox/install_generator.rb

Overview

OpenSandbox Ruby SDK

Wraps the open-sandbox.ai REST API for managing isolated container sandboxes.

Quick Start

client = OpenSandbox::Client.new

sandbox = client.sandboxes.create(
  image:      "python:3.11-slim",
  entrypoint: ["python", "-c", "print('hello')"],
  timeout:    300
)

client.sandboxes.wait_until(sandbox.id, target_state: OpenSandbox::SandboxState::RUNNING)
endpoint = client.sandboxes.endpoint(sandbox.id, port: 8080)
client.sandboxes.delete(sandbox.id)

Configuration

OpenSandbox.configure do |c|
  c.base_url = "https://api.open-sandbox.ai"
  c.api_key  = "sk-..."
  c.timeout  = 300
  c.logger   = Logger.new($stdout, level: :info)
end

Defined Under Namespace

Modules: Generators, LogUtils, SandboxState Classes: AuthenticationError, Client, Configuration, ConflictError, ConnectionError, Endpoint, Error, ForbiddenError, HttpClient, InvalidRequestError, NotFoundError, PaginationInfo, Pool, PoolCapacitySpec, Pools, Runner, Sandbox, SandboxList, SandboxStatus, Sandboxes, ServerError, ValidationError

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.clientObject

Shortcut: OpenSandbox.client (singleton, reset after configure)



61
62
63
# File 'lib/open_sandbox/client.rb', line 61

def client
  @client ||= Client.new
end

.configurationObject



51
52
53
# File 'lib/open_sandbox/client.rb', line 51

def configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



55
56
57
58
# File 'lib/open_sandbox/client.rb', line 55

def configure
  yield configuration
  reset_client!
end

.loggerObject

Convenience delegators



70
# File 'lib/open_sandbox/client.rb', line 70

def logger = configuration.logger

.reset_client!Object



65
66
67
# File 'lib/open_sandbox/client.rb', line 65

def reset_client!
  @client = nil
end