Class: Nexo::Sandboxes::Virtual
- Inherits:
-
Nexo::Sandbox
- Object
- Nexo::Sandbox
- Nexo::Sandboxes::Virtual
- Defined in:
- lib/nexo/sandboxes/virtual.rb
Overview
In-memory sandbox with zero host access — the safe default. Files live in a Hash keyed by normalized absolute path, so nothing the model writes ever touches the host filesystem.
#shell raises NotImplementedError on purpose: in-memory means there is
no process to run a command in. That is the safety property, not a gap.
Instance Method Summary collapse
- #glob(pattern) ⇒ Object
-
#initialize(cwd: "/workspace") ⇒ Virtual
constructor
Starts an empty in-memory filesystem rooted at
cwd(default/workspace). - #read(path) ⇒ Object
- #shell(_command) ⇒ Object
- #write(path, content) ⇒ Object
Methods inherited from Nexo::Sandbox
#close, #instructions, #mtime, #supports?
Constructor Details
#initialize(cwd: "/workspace") ⇒ Virtual
Starts an empty in-memory filesystem rooted at cwd (default /workspace).
13 14 15 16 |
# File 'lib/nexo/sandboxes/virtual.rb', line 13 def initialize(cwd: "/workspace") @cwd = cwd @files = {} end |
Instance Method Details
#glob(pattern) ⇒ Object
26 27 28 29 |
# File 'lib/nexo/sandboxes/virtual.rb', line 26 def glob(pattern) normalized = norm(pattern) @files.keys.select { |key| File.fnmatch(normalized, key) } end |
#read(path) ⇒ Object
18 19 20 |
# File 'lib/nexo/sandboxes/virtual.rb', line 18 def read(path) @files.fetch(norm(path)) { raise Errno::ENOENT, path } end |
#shell(_command) ⇒ Object
31 32 33 |
# File 'lib/nexo/sandboxes/virtual.rb', line 31 def shell(_command, **) raise NotImplementedError, "virtual sandbox has no shell" end |
#write(path, content) ⇒ Object
22 23 24 |
# File 'lib/nexo/sandboxes/virtual.rb', line 22 def write(path, content) @files[norm(path)] = content end |