Class: ActionAgent::MockSandboxBackend
- Inherits:
-
Object
- Object
- ActionAgent::MockSandboxBackend
- Defined in:
- app/services/action_agent/mock_sandbox_backend.rb
Overview
In-memory sandbox backend. Ships with the engine so the sandbox surface is exercisable in development and tests without any container runtime; backends that talk to real infrastructure are registered by the host app (see ActionAgent.sandbox_backends).
Instance Method Summary collapse
- #cleanup_expired ⇒ Object
- #create_sandbox(session, instance_tier: nil) ⇒ Object
-
#initialize ⇒ MockSandboxBackend
constructor
A new instance of MockSandboxBackend.
- #list_sandboxes ⇒ Object
- #status(sandbox_id) ⇒ Object
- #terminate(sandbox_id) ⇒ Object
Constructor Details
#initialize ⇒ MockSandboxBackend
Returns a new instance of MockSandboxBackend.
9 10 11 |
# File 'app/services/action_agent/mock_sandbox_backend.rb', line 9 def initialize @sandboxes = {} end |
Instance Method Details
#cleanup_expired ⇒ Object
48 49 50 |
# File 'app/services/action_agent/mock_sandbox_backend.rb', line 48 def cleanup_expired 0 end |
#create_sandbox(session, instance_tier: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/action_agent/mock_sandbox_backend.rb', line 13 def create_sandbox(session, instance_tier: nil) tier = instance_tier || SandboxInstanceTier.free_tier name = "mock-sandbox-#{SecureRandom.hex(4)}" @sandboxes[name] = { container_name: name, container_ip: "127.0.0.1", url: "http://127.0.0.1:8080", session_id: session.session_id, status: "running", instance_tier: tier.id, resources: { cpu_cores: tier.cpu_cores, memory_gb: tier.memory_gb, gpu: tier.gpu }, hourly_cost: tier.hourly_cost.to_f, created_at: Time.current } @sandboxes[name] end |
#list_sandboxes ⇒ Object
44 45 46 |
# File 'app/services/action_agent/mock_sandbox_backend.rb', line 44 def list_sandboxes @sandboxes.values end |
#status(sandbox_id) ⇒ Object
35 36 37 |
# File 'app/services/action_agent/mock_sandbox_backend.rb', line 35 def status(sandbox_id) @sandboxes[sandbox_id] || { status: "not_found" } end |
#terminate(sandbox_id) ⇒ Object
39 40 41 42 |
# File 'app/services/action_agent/mock_sandbox_backend.rb', line 39 def terminate(sandbox_id) @sandboxes.delete(sandbox_id) true end |