Class: RLM::Sandbox::UnsafeInProcess
- Defined in:
- lib/rlm/sandbox/unsafe_in_process.rb
Defined Under Namespace
Classes: Scope
Constant Summary collapse
- STREAM_CAPTURE_MUTEX =
Mutex.new
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#runtime_bridge ⇒ Object
readonly
Returns the value of attribute runtime_bridge.
-
#skills ⇒ Object
readonly
Returns the value of attribute skills.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
- #cleanup ⇒ Object
- #exec(code) ⇒ Object
- #execute(code) ⇒ Object
-
#initialize ⇒ UnsafeInProcess
constructor
A new instance of UnsafeInProcess.
- #prepare(context:, tools:, skills:, runtime_bridge:) ⇒ Object
- #prepared? ⇒ Boolean
Constructor Details
#initialize ⇒ UnsafeInProcess
Returns a new instance of UnsafeInProcess.
21 22 23 24 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 21 def initialize super @prepared = false end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
19 20 21 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 19 def context @context end |
#runtime_bridge ⇒ Object (readonly)
Returns the value of attribute runtime_bridge.
19 20 21 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 19 def runtime_bridge @runtime_bridge end |
#skills ⇒ Object (readonly)
Returns the value of attribute skills.
19 20 21 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 19 def skills @skills end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
19 20 21 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 19 def tools @tools end |
Instance Method Details
#cleanup ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 55 def cleanup @context = nil @tools = nil @skills = nil @runtime_bridge = nil @prepared = false end |
#exec(code) ⇒ Object
39 40 41 42 43 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 39 def exec(code) raise SandboxError, "Sandbox not prepared" unless prepared? execute(code) end |
#execute(code) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 45 def execute(code) stdout, stderr = capture_streams do Scope.new(runtime_bridge).instance_eval(code, "(rlm unsafe in-process sandbox)") end ExecutionResult.new(status: :ok, stdout: stdout, stderr: stderr) rescue StandardError => e ExecutionResult.new(status: :error, stderr: e., error: e, exit_code: 1) end |
#prepare(context:, tools:, skills:, runtime_bridge:) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 30 def prepare(context:, tools:, skills:, runtime_bridge:) @context = context @tools = tools @skills = skills @runtime_bridge = runtime_bridge @prepared = true ExecutionResult.new(status: :ok) end |
#prepared? ⇒ Boolean
26 27 28 |
# File 'lib/rlm/sandbox/unsafe_in_process.rb', line 26 def prepared? @prepared end |