Class: E2B::Models::SandboxInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/e2b/models/sandbox_info.rb

Overview

Information about a sandbox

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox_id:, template_id:, alias_name: nil, client_id: nil, started_at: nil, end_at: nil, cpu_count: nil, memory_mb: nil, metadata: {}, state: nil, sandbox_domain: nil, envd_version: nil) ⇒ SandboxInfo

Returns a new instance of SandboxInfo.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/e2b/models/sandbox_info.rb', line 64

def initialize(sandbox_id:, template_id:, alias_name: nil, client_id: nil,
               started_at: nil, end_at: nil, cpu_count: nil, memory_mb: nil, metadata: {},
               state: nil, sandbox_domain: nil, envd_version: nil)
  @sandbox_id = sandbox_id
  @template_id = template_id
  @alias_name = alias_name
  @client_id = client_id
  @started_at = started_at
  @end_at = end_at
  @cpu_count = cpu_count
  @memory_mb = memory_mb
  @metadata =  || {}
  @state = state
  @sandbox_domain = sandbox_domain
  @envd_version = envd_version
end

Instance Attribute Details

#alias_nameString? (readonly)

Returns Alias/name of the sandbox.

Returns:

  • (String, nil)

    Alias/name of the sandbox



14
15
16
# File 'lib/e2b/models/sandbox_info.rb', line 14

def alias_name
  @alias_name
end

#client_idString (readonly)

Returns Client ID.

Returns:

  • (String)

    Client ID



17
18
19
# File 'lib/e2b/models/sandbox_info.rb', line 17

def client_id
  @client_id
end

#cpu_countInteger (readonly)

Returns CPU count.

Returns:

  • (Integer)

    CPU count



26
27
28
# File 'lib/e2b/models/sandbox_info.rb', line 26

def cpu_count
  @cpu_count
end

#end_atTime (readonly)

Returns When the sandbox will end (timeout).

Returns:

  • (Time)

    When the sandbox will end (timeout)



23
24
25
# File 'lib/e2b/models/sandbox_info.rb', line 23

def end_at
  @end_at
end

#envd_versionString? (readonly)

Returns Envd version reported by the control plane.

Returns:

  • (String, nil)

    Envd version reported by the control plane



41
42
43
# File 'lib/e2b/models/sandbox_info.rb', line 41

def envd_version
  @envd_version
end

#memory_mbInteger (readonly)

Returns Memory in MB.

Returns:

  • (Integer)

    Memory in MB



29
30
31
# File 'lib/e2b/models/sandbox_info.rb', line 29

def memory_mb
  @memory_mb
end

#metadataHash (readonly)

Returns Metadata.

Returns:

  • (Hash)

    Metadata



32
33
34
# File 'lib/e2b/models/sandbox_info.rb', line 32

def 
  @metadata
end

#sandbox_domainString? (readonly)

Returns Domain where the sandbox is hosted.

Returns:

  • (String, nil)

    Domain where the sandbox is hosted



38
39
40
# File 'lib/e2b/models/sandbox_info.rb', line 38

def sandbox_domain
  @sandbox_domain
end

#sandbox_idString (readonly)

Returns Sandbox ID.

Returns:

  • (String)

    Sandbox ID



8
9
10
# File 'lib/e2b/models/sandbox_info.rb', line 8

def sandbox_id
  @sandbox_id
end

#started_atTime (readonly)

Returns When the sandbox was started.

Returns:

  • (Time)

    When the sandbox was started



20
21
22
# File 'lib/e2b/models/sandbox_info.rb', line 20

def started_at
  @started_at
end

#stateString? (readonly)

Returns Current sandbox state.

Returns:

  • (String, nil)

    Current sandbox state



35
36
37
# File 'lib/e2b/models/sandbox_info.rb', line 35

def state
  @state
end

#template_idString (readonly)

Returns Template ID used to create the sandbox.

Returns:

  • (String)

    Template ID used to create the sandbox



11
12
13
# File 'lib/e2b/models/sandbox_info.rb', line 11

def template_id
  @template_id
end

Class Method Details

.from_hash(data) ⇒ SandboxInfo

Create from API response hash

Parameters:

  • data (Hash)

    API response data

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/e2b/models/sandbox_info.rb', line 47

def self.from_hash(data)
  new(
    sandbox_id: data["sandboxID"] || data["sandbox_id"] || data[:sandboxID],
    template_id: data["templateID"] || data["template_id"] || data[:templateID],
    alias_name: data["alias"] || data[:alias],
    client_id: data["clientID"] || data["client_id"] || data[:clientID],
    started_at: parse_time(data["startedAt"] || data["started_at"] || data[:startedAt]),
    end_at: parse_time(data["endAt"] || data["end_at"] || data[:endAt]),
    cpu_count: data["cpuCount"] || data["cpu_count"] || data[:cpuCount],
    memory_mb: data["memoryMB"] || data["memory_mb"] || data[:memoryMB],
    metadata: data["metadata"] || data[:metadata] || {},
    state: data["state"] || data[:state],
    sandbox_domain: data["domain"] || data[:domain],
    envd_version: data["envdVersion"] || data["envd_version"] || data[:envdVersion]
  )
end

.parse_time(value) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/e2b/models/sandbox_info.rb', line 101

def self.parse_time(value)
  return nil if value.nil?
  return value if value.is_a?(Time)

  Time.parse(value.to_s)
rescue ArgumentError, TypeError
  nil
end

Instance Method Details

#running?Boolean

Check if sandbox is still running (not past end_at)

Returns:

  • (Boolean)


84
85
86
87
88
89
# File 'lib/e2b/models/sandbox_info.rb', line 84

def running?
  return false if @state == "paused"
  return true if @end_at.nil?

  Time.now < @end_at
end

#time_remainingInteger

Time remaining until timeout

Returns:

  • (Integer)

    Seconds remaining, 0 if expired



94
95
96
97
98
99
# File 'lib/e2b/models/sandbox_info.rb', line 94

def time_remaining
  return 0 if @end_at.nil?

  remaining = (@end_at - Time.now).to_i
  remaining.positive? ? remaining : 0
end