Class: Ask::Sandbox::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ask/sandbox/base.rb

Overview

Abstract base class for all sandbox providers.

A sandbox provider is responsible for executing commands in an isolated environment. Subclasses implement #call which runs a command and returns an Result.

Examples:

sandbox = Ask::Sandbox::Local.new
result = sandbox.call("ls -la", timeout: 10)
result.stdout  # => "..."
result.exit_code  # => 0

Direct Known Subclasses

Cloudflare, Daytona, Docker, Local

Instance Method Summary collapse

Instance Method Details

#call(command, timeout: 30, workdir: nil, env: {}, stdin: nil) ⇒ Ask::Sandbox::Result

Execute a command in the sandbox.

Parameters:

  • command (String, Array<String>)

    When a String, executed via a shell (bash -c). When an Array, executed directly with no shell interpretation.

  • timeout (Integer) (defaults to: 30)

    max execution time in seconds (default: 30)

  • workdir (String, nil) (defaults to: nil)

    working directory inside the sandbox

  • env (Hash{String => String}) (defaults to: {})

    extra environment variables

  • stdin (String, nil) (defaults to: nil)

    data to pipe to the command’s stdin

Returns:

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/ask/sandbox/base.rb', line 61

def call(command, timeout: 30, workdir: nil, env: {}, stdin: nil)
  raise NotImplementedError, "#{self.class} must implement #call(command, ...)"
end