Class: Rubyagents::Sandbox
- Inherits:
-
Object
- Object
- Rubyagents::Sandbox
- Defined in:
- lib/rubyagents/sandbox.rb
Defined Under Namespace
Classes: Executor, ForkExecutor, ThreadExecutor
Constant Summary collapse
- DEFAULT_TIMEOUT =
seconds
30- EXECUTOR =
Executor.for_platform.new
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #execute(code) ⇒ Object
-
#initialize(tools:, timeout: DEFAULT_TIMEOUT) ⇒ Sandbox
constructor
A new instance of Sandbox.
Constructor Details
#initialize(tools:, timeout: DEFAULT_TIMEOUT) ⇒ Sandbox
Returns a new instance of Sandbox.
90 91 92 93 94 |
# File 'lib/rubyagents/sandbox.rb', line 90 def initialize(tools:, timeout: DEFAULT_TIMEOUT) @tools = tools @timeout = timeout @tool_map = tools.each_with_object({}) { |t, h| h[t.class.tool_name] = t } end |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
88 89 90 |
# File 'lib/rubyagents/sandbox.rb', line 88 def timeout @timeout end |
Instance Method Details
#execute(code) ⇒ Object
96 97 98 |
# File 'lib/rubyagents/sandbox.rb', line 96 def execute(code) EXECUTOR.call(@timeout) { run_in_child(code) } end |