Class: LittleGhost::Sandboxes::Native

Inherits:
LittleGhost::Sandbox show all
Defined in:
lib/little_ghost/sandboxes/native.rb

Overview

Selects the operating system's built-in LittleGhost isolation backend. Selection fails closed on unsupported platforms and never falls back to unrestricted host execution.

Instance Attribute Summary

Attributes inherited from LittleGhost::Sandbox

#limits, #policy, #workspace

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LittleGhost::Sandbox

#allows?, #execute, providers, register_provider, resolve_provider, #supports?, #writable?

Constructor Details

#initialize(workspace:, platform: RUBY_PLATFORM, **options) ⇒ Native

Selects Seatbelt on macOS or Bubblewrap on Linux and builds that backend around workspace.



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/little_ghost/sandboxes/native.rb', line 24

def initialize(workspace:, platform: RUBY_PLATFORM, **options)
  implementation = if platform.include?("darwin")
    Seatbelt
  elsif platform.include?("linux")
    Bubblewrap
  else
    raise UnsupportedPlatformError, "native sandboxing is unavailable on #{platform}"
  end
  @backend = implementation.new(workspace:, platform:, **options)
  super(workspace:, policy: @backend.policy, limits: @backend.limits)
end

Class Method Details

.probe(platform: RUBY_PLATFORM, **options) ⇒ Object

Reports whether the native backend for platform is available and returns its capabilities.



11
12
13
14
15
16
17
18
19
20
# File 'lib/little_ghost/sandboxes/native.rb', line 11

def self.probe(platform: RUBY_PLATFORM, **options)
  implementation = if platform.include?("darwin")
    Seatbelt
  elsif platform.include?("linux")
    Bubblewrap
  else
    return {available: false, reason: "native sandboxing is unavailable on #{platform}", capabilities: Capabilities.new(features: [], network_modes: [])}
  end
  implementation.probe(platform:, **options)
end

Instance Method Details

#capabilitiesObject



37
# File 'lib/little_ghost/sandboxes/native.rb', line 37

def capabilities = @backend.capabilities

#closeObject



39
# File 'lib/little_ghost/sandboxes/native.rb', line 39

def close = @backend.close

#effective_policyObject



36
# File 'lib/little_ghost/sandboxes/native.rb', line 36

def effective_policy = @backend.effective_policy

#execute_programObject



44
# File 'lib/little_ghost/sandboxes/native.rb', line 44

def execute_program(...) = @backend.execute_program(...)

#listObject



41
# File 'lib/little_ghost/sandboxes/native.rb', line 41

def list(...) = @backend.list(...)

#open(run: nil) ⇒ Object



38
# File 'lib/little_ghost/sandboxes/native.rb', line 38

def open(run: nil) = @backend.open(run:)

#readObject



40
# File 'lib/little_ghost/sandboxes/native.rb', line 40

def read(...) = @backend.read(...)

#replaceObject



43
# File 'lib/little_ghost/sandboxes/native.rb', line 43

def replace(...) = @backend.replace(...)

#scopeObject



46
# File 'lib/little_ghost/sandboxes/native.rb', line 46

def scope(...) = @backend.scope(...)

#start_programObject



45
# File 'lib/little_ghost/sandboxes/native.rb', line 45

def start_program(...) = @backend.start_program(...)

#writeObject



42
# File 'lib/little_ghost/sandboxes/native.rb', line 42

def write(...) = @backend.write(...)