module MXC
Runs commands in sandboxes through Microsoft’s MXC.
result = MXC.run("python3 build.py", readable: "app/skills", writable: "tmp/out", timeout: 30) result.stdout
Constants
- VERSION
-
The gem version.
Public Class Methods
# File lib/mxc.rb, line 72 def availability(backend: config.backend, refresh: false) backend = Sandbox.backend_name(backend) @availability_lock.synchronize do @availability.delete(backend) if refresh @availability[backend] ||= Availability.probe(backend) end end
Returns the Availability of backend on this host, with the reason and remediation when it is unsupported. Pass refresh: true to probe the host again.
Source
# File lib/mxc.rb, line 81 def backends Native.backend_attributes.map { |attributes| Backend.new(**attributes) } end
Source
# File lib/mxc.rb, line 27 def config @config ||= Configuration.new end
Returns the global Configuration.
# File lib/mxc.rb, line 36 def configure yield config end
Yields the global Configuration to change the defaults every sandbox starts from.
MXC.configure do |config| config.timeout = 60 end
Source
# File lib/mxc.rb, line 51 def run(*command, **, &) sandbox(**).run(*command, &) end
Runs command in a new sandbox and returns its Result. Takes the command the same way as Sandbox#run, one String for the shell or a program and its arguments, and the same keywords as Sandbox.new. A block receives each Chunk of output as it arrives.
MXC.run("python3 build.py", readable: "app/skills", timeout: 30) MXC.run("python3", "convert.py", params[:filename], readable: "app/skills")
Source
# File lib/mxc.rb, line 41 def sandbox(**) Sandbox.new(**) end
Returns a new Sandbox, optionally configured with the same keywords as Sandbox.new.
Source
# File lib/mxc.rb, line 59 def spawn(*command, **) sandbox(**).spawn(*command) end
Starts command in a new sandbox and returns its Process. Takes the command the same way as Sandbox#run, and the same keywords as Sandbox.new.
MXC.spawn("python3", "-i", "-q", timeout: 60)
# File lib/mxc.rb, line 66 def supported?(backend: config.backend) availability(backend:).supported? end
Returns true when this host can start a sandbox with backend.
The answer comes from starting one real sandbox, once per backend and process.
Source
# File lib/mxc.rb, line 89 def supports?(capability) return false unless supported? case capability when :network then Preflight.problem(network: true).nil? when :network_policy then Preflight.problem(network: { allow: [] }).nil? && proxy_enforcement? else configured_backends.any? { |backend| backend.supports?(capability) } end end
Returns true when this host supports capability with the configured backend.
capability is :network for unrestricted network access, :network_policy for host allow-lists, or any capability a Backend reports.