Skip to content
Kward Search API index

Module: Kward::Sandbox::Environment

Defined in:
lib/kward/sandbox/environment.rb

Overview

Builds a minimal environment for sandboxed command workers. In particular, credentials and language-runtime injection variables are not inherited.

Constant Summary collapse

SAFE_VARIABLES =
%w[PATH LANG LC_ALL LC_CTYPE TERM COLORTERM NO_COLOR].freeze

Class Method Summary collapse

Class Method Details

.command_worker(temporary_root, source: ENV) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/kward/sandbox/environment.rb', line 11

def command_worker(temporary_root, source: ENV)
  SAFE_VARIABLES.each_with_object({}) do |name, environment|
    value = source[name].to_s
    environment[name] = value unless value.empty?
  end.merge(
    "HOME" => temporary_root,
    "TMPDIR" => temporary_root,
    "TMP" => temporary_root,
    "TEMP" => temporary_root
  )
end