Repository: e2b-dev/infra
Pull request #389: Refactor codebase to support platform compile flags
Author: login: r33drichards
Labels: name: improvement
description: Improvement for current functionality
Created: 2025-03-06T20:13:18Z | Merged: 2025-03-08T00:31:54Z

Introduces a [test](https://github.com/e2b-dev/infra/pull/389/files#diff-1dfbd4dd5139cb078d736bead7ec8b9af7219a0dd0c6d8ad7466da25bf7305ecR22) for orchestrator and adds supporting changes to allow running this test. 

These changes include 

- separate code paths for linux and non linux platforms in order to run tests on macos 
- get environment variable from struct field instead of global variable to avoid panics when executing test
- get device pool as a function instead of using init to set global var which avoids tests failing in CI/CD [see this run](https://github.com/e2b-dev/infra/actions/runs/13710316540/job/38345255701?pr=389)


Diff:
diff --git a/packages/orchestrator/cmd/mock-nbd/mock.go b/packages/orchestrator/cmd/mock-nbd/mock.go
index f7df41f3e1..69cc1b7e23 100644
--- a/packages/orchestrator/cmd/mock-nbd/mock.go
+++ b/packages/orchestrator/cmd/mock-nbd/mock.go
@@ -47,6 +47,12 @@ func main() {
 
 	done := make(chan os.Signal, 1)
 	signal.Notify(done, os.Interrupt)
+	devicePool, err := nbd.NewDevicePool()
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "failed to create device pool: %v\n", err)
+
+		return
+	}
 
 	go func() {
 		<-done
@@ -63,7 +69,7 @@ func main() {
 		fmt.Printf("----------------------------------------\n")
 		fmt.Printf("[%d] starting mock nbd server\n", i)
 
-		readData, err := MockNbd(ctx, device, i)
+		readData, err := MockNbd(ctx, device, i, devicePool)
 		if err != nil {
 			fmt.Fprintf(os.Stderr, "[%d] failed to mock nbd: %v\n", i, err)
 
@@ -78,7 +84,7 @@ func main() {
 	}
 }
 
-func MockNbd(ctx context.Context, device *DeviceWithClose, index int) ([]byte, error) {
+func MockNbd(ctx context.Context, device *DeviceWithClose, index int, devicePool *nbd.DevicePool) ([]byte, error) {
 	ctx, cancel := context.WithCancel(ctx)
 	defer cancel()
 
@@ -87,7 +93,7 @@ func MockNbd(ctx context.Context, device *DeviceWithClose, index int) ([]byte, e
 		return nil, fmt.Errorf("failed to get size: %w", err)
 	}
 
-	deviceIndex, err := nbd.Pool.GetDevice(ctx)
+	deviceIndex, err := devicePool.GetDevice(ctx)
 	if err != nil {
 		return nil, fmt.Errorf("failed to get device: %w", err)
 	}
@@ -99,7 +105,7 @@ func MockNbd(ctx context.Context, device *DeviceWithClose, index int) ([]byte, e
 
 		for {
 			counter += 1
-			err = nbd.Pool.ReleaseDevice(deviceIndex)
+			err = devicePool.ReleaseDevice(deviceIndex)
 			if err != nil {
 				if counter%10 == 0 {
 					fmt.Printf("[%d] failed to release device: %v\n", index, err)
@@ -118,7 +124,7 @@ func MockNbd(ctx context.Context, device *DeviceWithClose, index int) ([]byte, e
 		}
 	}()
 
-	mnt = nbd.NewDirectPathMount(device)
+	mnt = nbd.NewDirectPathMount(device, devicePool)
 
 	go func() {
 		<-ctx.Done()
diff --git a/packages/orchestrator/cmd/mock-sandbox/mock.go b/packages/orchestrator/cmd/mock-sandbox/mock.go
index 3c243f0055..4a7631e5d7 100644
--- a/packages/orchestrator/cmd/mock-sandbox/mock.go
+++ b/packages/orchestrator/cmd/mock-sandbox/mock.go
@@ -14,10 +14,11 @@ import (
 
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/dns"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template"
 	"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
-	"github.com/e2b-dev/infra/packages/shared/pkg/logger/sandbox"
+	sbxlogger "github.com/e2b-dev/infra/packages/shared/pkg/logger/sandbox"
 )
 
 func main() {
@@ -27,6 +28,13 @@ func main() {
 	keepAlive := flag.Int("alive", 0, "keep alive")
 	count := flag.Int("count", 1, "number of serially spawned sandboxes")
 
+	devicePool, err := nbd.NewDevicePool()
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "failed to create device pool: %v\n", err)
+
+		return
+	}
+
 	flag.Parse()
 
 	ctx, cancel := context.WithCancel(context.Background())
@@ -58,7 +66,7 @@ func main() {
 		return
 	}
 
-	networkPool, err := network.NewPool(ctx, *count, 0)
+	networkPool, err := network.NewPool(ctx, *count, 0, "mock-node")
 	if err != nil {
 		fmt.Fprintf(os.Stderr, "failed to create network pool: %v\n", err)
 
@@ -81,6 +89,7 @@ func main() {
 			time.Duration(*keepAlive)*time.Second,
 			networkPool,
 			templateCache,
+			devicePool,
 		)
 		if err != nil {
 			break
@@ -97,6 +106,7 @@ func mockSandbox(
 	keepAlive time.Duration,
 	networkPool *network.Pool,
 	templateCache *template.Cache,
+	devicePool *nbd.DevicePool,
 ) error {
 	tracer := otel.Tracer(fmt.Sprintf("sandbox-%s", sandboxId))
 	childCtx, _ := tracer.Start(ctx, "mock-sandbox")
@@ -137,6 +147,8 @@ func mockSandbox(
 		time.Now(),
 		true,
 		templateId,
+		"test-client",
+		devicePool,
 	)
 	defer func() {
 		cleanupErr := cleanup.Run()
diff --git a/packages/orchestrator/cmd/mock-snapshot/mock.go b/packages/orchestrator/cmd/mock-snapshot/mock.go
index 4a9f771ed7..40ca06760f 100644
--- a/packages/orchestrator/cmd/mock-snapshot/mock.go
+++ b/packages/orchestrator/cmd/mock-snapshot/mock.go
@@ -15,6 +15,7 @@ import (
 
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/dns"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template"
 	"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
@@ -31,6 +32,12 @@ func main() {
 
 	flag.Parse()
 
+	devicePool, err := nbd.NewDevicePool()
+	if err != nil {
+		fmt.Fprintf(os.Stderr, "failed to create device pool: %v\n", err)
+		return
+	}
+
 	ctx, cancel := context.WithCancel(context.Background())
 	defer cancel()
 
@@ -60,7 +67,7 @@ func main() {
 		return
 	}
 
-	networkPool, err := network.NewPool(ctx, *count, 0)
+	networkPool, err := network.NewPool(ctx, *count, 0, "mock-node")
 	if err != nil {
 		fmt.Fprintf(os.Stderr, "failed to create network pool: %v\n", err)
 
@@ -85,6 +92,7 @@ func main() {
 			time.Duration(*keepAlive)*time.Second,
 			networkPool,
 			templateCache,
+			devicePool,
 		)
 		if err != nil {
 			fmt.Fprintf(os.Stderr, "failed to start sandbox: %v\n", err)
@@ -107,6 +115,7 @@ func mockSnapshot(
 	keepAlive time.Duration,
 	networkPool *network.Pool,
 	templateCache *template.Cache,
+	devicePool *nbd.DevicePool,
 ) error {
 	tracer := otel.Tracer(fmt.Sprintf("sandbox-%s", sandboxId))
 	childCtx, _ := tracer.Start(ctx, "mock-sandbox")
@@ -145,6 +154,8 @@ func mockSnapshot(
 		time.Now(),
 		false,
 		templateId,
+		"test-client",
+		devicePool,
 	)
 	defer func() {
 		cleanupErr := cleanup.Run()
@@ -245,6 +256,8 @@ func mockSnapshot(
 		time.Now(),
 		false,
 		templateId,
+		"test-client",
+		devicePool,
 	)
 	defer func() {
 		cleanupErr := cleanup2.Run()
diff --git a/packages/orchestrator/internal/consul/node.go b/packages/orchestrator/internal/consul/node.go
index 3b6323c05d..8ccd4da145 100644
--- a/packages/orchestrator/internal/consul/node.go
+++ b/packages/orchestrator/internal/consul/node.go
@@ -6,8 +6,8 @@ import (
 
 const shortNodeIDLength = 8
 
-var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
-	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
-)
+func GetClientID() string {
+	nodeID := utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	return nodeID[:shortNodeIDLength]
+}
diff --git a/packages/orchestrator/internal/sandbox/fc/client.go b/packages/orchestrator/internal/sandbox/fc/client_linux.go
similarity index 98%
rename from packages/orchestrator/internal/sandbox/fc/client.go
rename to packages/orchestrator/internal/sandbox/fc/client_linux.go
index 6a8d59f8d7..1c3f9a26f4 100644
--- a/packages/orchestrator/internal/sandbox/fc/client.go
+++ b/packages/orchestrator/internal/sandbox/fc/client_linux.go
@@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
+
 package fc
 
 import (
diff --git a/packages/orchestrator/internal/sandbox/fc/client_other.go b/packages/orchestrator/internal/sandbox/fc/client_other.go
new file mode 100644
index 0000000000..53d5bd7c4b
--- /dev/null
+++ b/packages/orchestrator/internal/sandbox/fc/client_other.go
@@ -0,0 +1,37 @@
+//go:build !linux
+// +build !linux
+
+package fc
+
+import (
+	"context"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template"
+)
+
+type apiClient struct {
+}
+
+func newApiClient(socketPath string) *apiClient {
+	return nil
+}
+
+func (c *apiClient) loadSnapshot(ctx context.Context, uffdSocketPath string, uffdReady chan struct{}, snapfile template.File) error {
+	return nil
+}
+
+func (c *apiClient) resumeVM(ctx context.Context) error {
+	return nil
+}
+
+func (c *apiClient) setMmds(ctx context.Context, metadata *MmdsMetadata) error {
+	return nil
+}
+
+func (c *apiClient) pauseVM(ctx context.Context) error {
+	return nil
+}
+
+func (c *apiClient) createSnapshot(ctx context.Context, snapfilePath string, memfilePath string) error {
+	return nil
+}
diff --git a/packages/orchestrator/internal/sandbox/nbd/path_direct.go b/packages/orchestrator/internal/sandbox/nbd/path_direct_linux.go
similarity index 90%
rename from packages/orchestrator/internal/sandbox/nbd/path_direct.go
rename to packages/orchestrator/internal/sandbox/nbd/path_direct_linux.go
index e019e35a24..87d0a45985 100644
--- a/packages/orchestrator/internal/sandbox/nbd/path_direct.go
+++ b/packages/orchestrator/internal/sandbox/nbd/path_direct_linux.go
@@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
+
 package nbd
 
 import (
@@ -22,16 +25,18 @@ type DirectPathMount struct {
 	deviceIndex uint32
 	blockSize   uint64
 	cancelfn    context.CancelFunc
+	devicePool  *DevicePool
 }
 
-func NewDirectPathMount(b block.Device) *DirectPathMount {
+func NewDirectPathMount(b block.Device, devicePool *DevicePool) *DirectPathMount {
 	ctx, cancelfn := context.WithCancel(context.Background())
 
 	return &DirectPathMount{
-		Backend:   b,
-		ctx:       ctx,
-		cancelfn:  cancelfn,
-		blockSize: 4096,
+		Backend:    b,
+		ctx:        ctx,
+		cancelfn:   cancelfn,
+		blockSize:  4096,
+		devicePool: devicePool,
 	}
 }
 
@@ -42,7 +47,7 @@ func (d *DirectPathMount) Open(ctx context.Context) (uint32, error) {
 	}
 
 	for {
-		d.deviceIndex, err = Pool.GetDevice(ctx)
+		d.deviceIndex, err = d.devicePool.GetDevice(ctx)
 		if err != nil {
 			return 0, err
 		}
@@ -93,7 +98,7 @@ func (d *DirectPathMount) Open(ctx context.Context) (uint32, error) {
 			zap.L().Error("error closing conn", zap.Error(connErr))
 		}
 
-		releaseErr := Pool.ReleaseDevice(d.deviceIndex)
+		releaseErr := d.devicePool.ReleaseDevice(d.deviceIndex)
 		if releaseErr != nil {
 			zap.L().Error("error releasing device", zap.Error(releaseErr))
 		}
diff --git a/packages/orchestrator/internal/sandbox/nbd/path_direct_other.go b/packages/orchestrator/internal/sandbox/nbd/path_direct_other.go
new file mode 100644
index 0000000000..44c76a56fe
--- /dev/null
+++ b/packages/orchestrator/internal/sandbox/nbd/path_direct_other.go
@@ -0,0 +1,27 @@
+//go:build !linux
+// +build !linux
+
+package nbd
+
+import (
+	"context"
+	"errors"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block"
+)
+
+type DirectPathMount struct {
+	Backend block.Device
+}
+
+func NewDirectPathMount(b block.Device, devicePool *DevicePool) *DirectPathMount {
+	return nil
+}
+
+func (d *DirectPathMount) Open(ctx context.Context) (uint32, error) {
+	return 0, errors.New("platform does not support direct path mount")
+}
+
+func (d *DirectPathMount) Close() error {
+	return errors.New("platform does not support direct path mount")
+}
diff --git a/packages/orchestrator/internal/sandbox/nbd/pool.go b/packages/orchestrator/internal/sandbox/nbd/pool.go
index af38e36b0f..31c9f1e4e2 100644
--- a/packages/orchestrator/internal/sandbox/nbd/pool.go
+++ b/packages/orchestrator/internal/sandbox/nbd/pool.go
@@ -57,21 +57,19 @@ type DevicePool struct {
 	slotCounter metric.Int64UpDownCounter
 }
 
-var Pool *DevicePool
-
-func init() {
+func NewDevicePool() (*DevicePool, error) {
 	maxDevices, err := getMaxDevices()
 	if err != nil {
-		panic(fmt.Errorf("failed to get current max devices: %w", err))
+		return nil, fmt.Errorf("failed to get max devices: %w", err)
 	}
 
 	if maxDevices == 0 {
-		panic(fmt.Errorf("nbd module is not loaded or max devices is set to 0"))
+		return nil, errors.New("max devices is 0")
 	}
 
 	counter, err := meters.GetUpDownCounter(meters.NBDkSlotSReadyPoolCounterMeterName)
 	if err != nil {
-		panic(fmt.Errorf("failed to get nbd slot pool counter: %w", err))
+		return nil, fmt.Errorf("failed to get slot pool counter: %w", err)
 	}
 
 	pool := &DevicePool{
@@ -88,7 +86,7 @@ func init() {
 		}
 	}()
 
-	Pool = pool
+	return pool, nil
 }
 
 func getMaxDevices() (uint, error) {
diff --git a/packages/orchestrator/internal/sandbox/network/host.go b/packages/orchestrator/internal/sandbox/network/host_linux.go
similarity index 97%
rename from packages/orchestrator/internal/sandbox/network/host.go
rename to packages/orchestrator/internal/sandbox/network/host_linux.go
index 198b9e2b11..6814b32a6f 100644
--- a/packages/orchestrator/internal/sandbox/network/host.go
+++ b/packages/orchestrator/internal/sandbox/network/host_linux.go
@@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
+
 package network
 
 import (
diff --git a/packages/orchestrator/internal/sandbox/network/host_other.go b/packages/orchestrator/internal/sandbox/network/host_other.go
new file mode 100644
index 0000000000..9c8dadaa38
--- /dev/null
+++ b/packages/orchestrator/internal/sandbox/network/host_other.go
@@ -0,0 +1,7 @@
+//go:build !linux
+// +build !linux
+
+package network
+
+// Host loopback interface name
+const loopbackInterface = "lo"
diff --git a/packages/orchestrator/internal/sandbox/network/network.go b/packages/orchestrator/internal/sandbox/network/network_linux.go
similarity index 99%
rename from packages/orchestrator/internal/sandbox/network/network.go
rename to packages/orchestrator/internal/sandbox/network/network_linux.go
index 32307096b1..1641f68204 100644
--- a/packages/orchestrator/internal/sandbox/network/network.go
+++ b/packages/orchestrator/internal/sandbox/network/network_linux.go
@@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
+
 package network
 
 import (
diff --git a/packages/orchestrator/internal/sandbox/network/network_other.go b/packages/orchestrator/internal/sandbox/network/network_other.go
new file mode 100644
index 0000000000..87717a8487
--- /dev/null
+++ b/packages/orchestrator/internal/sandbox/network/network_other.go
@@ -0,0 +1,16 @@
+//go:build !linux
+// +build !linux
+
+package network
+
+import (
+	"errors"
+)
+
+func (s *Slot) CreateNetwork() error {
+	return errors.New("platform does not support network creation")
+}
+
+func (s *Slot) RemoveNetwork() error {
+	return errors.New("platform does not support network removal")
+}
diff --git a/packages/orchestrator/internal/sandbox/network/pool.go b/packages/orchestrator/internal/sandbox/network/pool.go
index da79f1df1e..9ac1f09ab6 100644
--- a/packages/orchestrator/internal/sandbox/network/pool.go
+++ b/packages/orchestrator/internal/sandbox/network/pool.go
@@ -29,7 +29,7 @@ type Pool struct {
 	slotStorage Storage
 }
 
-func NewPool(ctx context.Context, newSlotsPoolSize, reusedSlotsPoolSize int) (*Pool, error) {
+func NewPool(ctx context.Context, newSlotsPoolSize, reusedSlotsPoolSize int, clientID string) (*Pool, error) {
 	newSlots := make(chan Slot, newSlotsPoolSize-1)
 	reusedSlots := make(chan Slot, reusedSlotsPoolSize)
 
@@ -43,7 +43,7 @@ func NewPool(ctx context.Context, newSlotsPoolSize, reusedSlotsPoolSize int) (*P
 		return nil, fmt.Errorf("failed to create reused slot counter: %w", err)
 	}
 
-	slotStorage, err := NewStorage(slotsSize)
+	slotStorage, err := NewStorage(slotsSize, clientID)
 	if err != nil {
 		return nil, fmt.Errorf("failed to create slot storage: %w", err)
 	}
diff --git a/packages/orchestrator/internal/sandbox/network/storage.go b/packages/orchestrator/internal/sandbox/network/storage.go
index 951705f17b..79fc3a8abd 100644
--- a/packages/orchestrator/internal/sandbox/network/storage.go
+++ b/packages/orchestrator/internal/sandbox/network/storage.go
@@ -8,10 +8,10 @@ type Storage interface {
 }
 
 // NewStorage creates a new slot storage based on the environment, we are ok with using a memory storage for local
-func NewStorage(slotsSize int) (Storage, error) {
+func NewStorage(slotsSize int, clientID string) (Storage, error) {
 	if env.IsLocal() {
 		return NewStorageMemory(slotsSize)
 	} else {
-		return NewStorageKV(slotsSize)
+		return NewStorageKV(slotsSize, clientID)
 	}
 }
diff --git a/packages/orchestrator/internal/sandbox/network/storage_kv.go b/packages/orchestrator/internal/sandbox/network/storage_kv.go
index 4f699de16b..78f59dadb0 100644
--- a/packages/orchestrator/internal/sandbox/network/storage_kv.go
+++ b/packages/orchestrator/internal/sandbox/network/storage_kv.go
@@ -7,16 +7,20 @@ import (
 
 	consulApi "github.com/hashicorp/consul/api"
 
-	"github.com/e2b-dev/infra/packages/orchestrator/internal/consul"
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 type StorageKV struct {
 	slotsSize    int
 	consulClient *consulApi.Client
+	clientID     string
 }
 
-func NewStorageKV(slotsSize int) (*StorageKV, error) {
+func (s *StorageKV) getKVKey(slotIdx int) string {
+	return fmt.Sprintf("%s/%d", s.clientID, slotIdx)
+}
+
+func NewStorageKV(slotsSize int, clientID string) (*StorageKV, error) {
 	consulToken := utils.RequiredEnv("CONSUL_TOKEN", "Consul token for authenticating requests to the Consul API")
 
 	consulClient, err := newConsulClient(consulToken)
@@ -27,6 +31,7 @@ func NewStorageKV(slotsSize int) (*StorageKV, error) {
 	return &StorageKV{
 		slotsSize:    slotsSize,
 		consulClient: consulClient,
+		clientID:     clientID,
 	}, nil
 }
 
@@ -65,7 +70,7 @@ func (s *StorageKV) Acquire() (*Slot, error) {
 
 	for randomTry := 1; randomTry <= 10; randomTry++ {
 		slotIdx := rand.Intn(s.slotsSize)
-		key := getKVKey(slotIdx)
+		key := s.getKVKey(slotIdx)
 
 		maybeSlot, err := trySlot(slotIdx, key)
 		if err != nil {
@@ -83,13 +88,13 @@ func (s *StorageKV) Acquire() (*Slot, error) {
 		// This is a fallback for the case when all slots are taken.
 		// There is no Consul lock so it's possible that multiple sandboxes will try to acquire the same slot.
 		// In this case, only one of them will succeed and other will try with different slots.
-		reservedKeys, _, keysErr := kv.Keys(consul.ClientID+"/", "", nil)
+		reservedKeys, _, keysErr := kv.Keys(s.clientID+"/", "", nil)
 		if keysErr != nil {
 			return nil, fmt.Errorf("failed to read Consul KV: %w", keysErr)
 		}
 
 		for slotIdx := 0; slotIdx < s.slotsSize; slotIdx++ {
-			key := getKVKey(slotIdx)
+			key := s.getKVKey(slotIdx)
 
 			if slices.Contains(reservedKeys, key) {
 				continue
@@ -141,7 +146,3 @@ func (s *StorageKV) Release(ips *Slot) error {
 
 	return nil
 }
-
-func getKVKey(slotIdx int) string {
-	return fmt.Sprintf("%s/%d", consul.ClientID, slotIdx)
-}
diff --git a/packages/orchestrator/internal/sandbox/rootfs/cow.go b/packages/orchestrator/internal/sandbox/rootfs/cow.go
index 5dff32bd54..f3d13a0d96 100644
--- a/packages/orchestrator/internal/sandbox/rootfs/cow.go
+++ b/packages/orchestrator/internal/sandbox/rootfs/cow.go
@@ -26,9 +26,10 @@ type CowDevice struct {
 	BaseBuildId string
 
 	finishedOperations chan struct{}
+	devicePool         *nbd.DevicePool
 }
 
-func NewCowDevice(rootfs *template.Storage, cachePath string, blockSize int64) (*CowDevice, error) {
+func NewCowDevice(rootfs *template.Storage, cachePath string, blockSize int64, devicePool *nbd.DevicePool) (*CowDevice, error) {
 	size, err := rootfs.Size()
 	if err != nil {
 		return nil, fmt.Errorf("error getting device size: %w", err)
@@ -41,7 +42,7 @@ func NewCowDevice(rootfs *template.Storage, cachePath string, blockSize int64) (
 
 	overlay := block.NewOverlay(rootfs, cache, blockSize)
 
-	mnt := nbd.NewDirectPathMount(overlay)
+	mnt := nbd.NewDirectPathMount(overlay, devicePool)
 
 	return &CowDevice{
 		mnt:                mnt,
@@ -50,6 +51,7 @@ func NewCowDevice(rootfs *template.Storage, cachePath string, blockSize int64) (
 		blockSize:          blockSize,
 		finishedOperations: make(chan struct{}, 1),
 		BaseBuildId:        rootfs.Header().Metadata.BaseBuildId.String(),
+		devicePool:         devicePool,
 	}, nil
 }
 
@@ -123,7 +125,7 @@ func (o *CowDevice) Close() error {
 	attempts := 0
 	for {
 		attempts++
-		err := nbd.Pool.ReleaseDevice(slot)
+		err := o.devicePool.ReleaseDevice(slot)
 		if errors.Is(err, nbd.ErrDeviceInUse{}) {
 			if attempts%100 == 0 {
 				zap.L().Info("error releasing overlay device", zap.Int("attempts", attempts), zap.Error(err))
diff --git a/packages/orchestrator/internal/sandbox/sandbox.go b/packages/orchestrator/internal/sandbox/sandbox_linux.go
similarity index 98%
rename from packages/orchestrator/internal/sandbox/sandbox.go
rename to packages/orchestrator/internal/sandbox/sandbox_linux.go
index 9261356ead..6b6ed5ae6d 100644
--- a/packages/orchestrator/internal/sandbox/sandbox.go
+++ b/packages/orchestrator/internal/sandbox/sandbox_linux.go
@@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
+
 package sandbox
 
 import (
@@ -20,6 +23,7 @@ import (
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/dns"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/fc"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/rootfs"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/stats"
@@ -84,6 +88,8 @@ func NewSandbox(
 	endAt time.Time,
 	isSnapshot bool,
 	baseTemplateID string,
+	clientID string,
+	devicePool *nbd.DevicePool,
 ) (*Sandbox, *Cleanup, error) {
 	childCtx, childSpan := tracer.Start(ctx, "new-sandbox")
 	defer childSpan.End()
@@ -143,6 +149,7 @@ func NewSandbox(
 		readonlyRootfs,
 		sandboxFiles.SandboxCacheRootfsPath(),
 		sandboxFiles.RootfsBlockSize(),
+		devicePool,
 	)
 	if err != nil {
 		return nil, cleanup, fmt.Errorf("failed to create overlay file: %w", err)
@@ -167,7 +174,7 @@ func NewSandbox(
 	}
 	overlaySpan.End()
 
-	fcUffd, uffdErr := uffd.New(memfile, sandboxFiles.SandboxUffdSocketPath(), sandboxFiles.MemfilePageSize())
+	fcUffd, uffdErr := uffd.New(memfile, sandboxFiles.SandboxUffdSocketPath(), sandboxFiles.MemfilePageSize(), clientID)
 	if uffdErr != nil {
 		return nil, cleanup, fmt.Errorf("failed to create uffd: %w", uffdErr)
 	}
diff --git a/packages/orchestrator/internal/sandbox/sandbox_other.go b/packages/orchestrator/internal/sandbox/sandbox_other.go
new file mode 100644
index 0000000000..3f8ccad64b
--- /dev/null
+++ b/packages/orchestrator/internal/sandbox/sandbox_other.go
@@ -0,0 +1,104 @@
+//go:build !linux
+// +build !linux
+
+package sandbox
+
+import (
+	"context"
+	"errors"
+	"fmt"
+	"net/http"
+	"sync/atomic"
+	"time"
+
+	"go.opentelemetry.io/otel/trace"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/dns"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template"
+	"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
+	sbxlogger "github.com/e2b-dev/infra/packages/shared/pkg/logger/sandbox"
+	"github.com/e2b-dev/infra/packages/shared/pkg/storage"
+	"github.com/e2b-dev/infra/packages/shared/pkg/storage/header"
+)
+
+var httpClient = http.Client{
+	Timeout: 10 * time.Second,
+}
+
+type NoOpProcess struct {
+	Exit chan error
+}
+
+type NoOpCleanup struct {
+}
+
+func (m *NoOpCleanup) Run() error {
+	return errors.New("platform does not support sandbox")
+}
+
+type Sandbox struct {
+	Config    *orchestrator.SandboxConfig
+	process   NoOpProcess
+	uffdExit  chan error
+	cleanup   NoOpCleanup
+	healthy   atomic.Bool
+	Slot      network.Slot
+	EndAt     time.Time
+	StartedAt time.Time
+}
+
+func (s *Sandbox) LoggerMetadata() sbxlogger.SandboxMetadata {
+	panic("platform does not support sandbox")
+}
+
+// Run cleanup functions for the already initialized resources if there is any error or after you are done with the started sandbox.
+func NewSandbox(
+	ctx context.Context,
+	tracer trace.Tracer,
+	dns *dns.DNS,
+	networkPool *network.Pool,
+	templateCache *template.Cache,
+	config *orchestrator.SandboxConfig,
+	traceID string,
+	startedAt time.Time,
+	endAt time.Time,
+	isSnapshot bool,
+	baseTemplateID string,
+	clientID string,
+	devicePool *nbd.DevicePool,
+) (*Sandbox, *Cleanup, error) {
+	return nil, nil, errors.New("platform does not support sandbox")
+}
+
+func (s *Sandbox) Wait() error {
+	return errors.New("platform does not support sandbox")
+}
+
+func (s *Sandbox) Stop() error {
+	err := s.cleanup.Run()
+	if err != nil {
+		return fmt.Errorf("failed to stop sandbox: %w", err)
+	}
+
+	return nil
+}
+
+func (s *Sandbox) Snapshot(
+	ctx context.Context,
+	tracer trace.Tracer,
+	snapshotTemplateFiles *storage.TemplateCacheFiles,
+	releaseLock func(),
+) (*Snapshot, error) {
+	return nil, errors.New("platform does not support snapshot")
+}
+
+type Snapshot struct {
+	MemfileDiff       build.Diff
+	MemfileDiffHeader *header.Header
+	RootfsDiff        build.Diff
+	RootfsDiffHeader  *header.Header
+	Snapfile          *template.LocalFile
+}
diff --git a/packages/orchestrator/internal/sandbox/uffd/handler.go b/packages/orchestrator/internal/sandbox/uffd/handler.go
index 6912dca49b..2b1bb8b985 100644
--- a/packages/orchestrator/internal/sandbox/uffd/handler.go
+++ b/packages/orchestrator/internal/sandbox/uffd/handler.go
@@ -44,6 +44,7 @@ type Uffd struct {
 
 	memfile    *block.TrackedSliceDevice
 	socketPath string
+	clientID   string
 }
 
 func (u *Uffd) Disable() error {
@@ -54,7 +55,7 @@ func (u *Uffd) Dirty() *bitset.BitSet {
 	return u.memfile.Dirty()
 }
 
-func New(memfile block.ReadonlyDevice, socketPath string, blockSize int64) (*Uffd, error) {
+func New(memfile block.ReadonlyDevice, socketPath string, blockSize int64, clientID string) (*Uffd, error) {
 	pRead, pWrite, err := os.Pipe()
 	if err != nil {
 		return nil, fmt.Errorf("failed to create exit fd: %w", err)
@@ -80,6 +81,7 @@ func New(memfile block.ReadonlyDevice, socketPath string, blockSize int64) (*Uff
 
 			return nil
 		}),
+		clientID: clientID,
 	}, nil
 }
 
@@ -181,7 +183,15 @@ func (u *Uffd) handle(sandboxId string) (err error) {
 
 	u.Ready <- struct{}{}
 
-	err = Serve(int(uffd), setup.Mappings, u.memfile, u.exitReader.Fd(), u.Stop, sandboxId)
+	err = Serve(
+		int(uffd),
+		setup.Mappings,
+		u.memfile,
+		u.exitReader.Fd(),
+		u.Stop,
+		sandboxId,
+		u.clientID,
+	)
 	if err != nil {
 		return fmt.Errorf("failed handling uffd: %w", err)
 	}
diff --git a/packages/orchestrator/internal/sandbox/uffd/serve.go b/packages/orchestrator/internal/sandbox/uffd/serve_linux.go
similarity index 82%
rename from packages/orchestrator/internal/sandbox/uffd/serve.go
rename to packages/orchestrator/internal/sandbox/uffd/serve_linux.go
index b17c6aaf54..547225a61d 100644
--- a/packages/orchestrator/internal/sandbox/uffd/serve.go
+++ b/packages/orchestrator/internal/sandbox/uffd/serve_linux.go
@@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
+
 package uffd
 
 import (
@@ -11,7 +14,6 @@ import (
 	"golang.org/x/sync/errgroup"
 	"golang.org/x/sys/unix"
 
-	"github.com/e2b-dev/infra/packages/orchestrator/internal/consul"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block"
 )
 
@@ -36,7 +38,15 @@ func getMapping(addr uintptr, mappings []GuestRegionUffdMapping) (*GuestRegionUf
 	return nil, fmt.Errorf("address %d not found in any mapping", addr)
 }
 
-func Serve(uffd int, mappings []GuestRegionUffdMapping, src *block.TrackedSliceDevice, fd uintptr, stop func() error, sandboxId string) error {
+func Serve(
+	uffd int,
+	mappings []GuestRegionUffdMapping,
+	src *block.TrackedSliceDevice,
+	fd uintptr,
+	stop func() error,
+	sandboxId string,
+	nodeID string,
+) error {
 	pollFds := []unix.PollFd{
 		{Fd: int32(uffd), Events: unix.POLLIN},
 		{Fd: int32(fd), Events: unix.POLLIN},
@@ -62,7 +72,7 @@ outerLoop:
 				continue
 			}
 
-			zap.L().Error("UFFD serve polling error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", consul.ClientID))
+			zap.L().Error("UFFD serve polling error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", nodeID))
 
 			return fmt.Errorf("failed polling: %w", err)
 		}
@@ -71,7 +81,7 @@ outerLoop:
 		if exitFd.Revents&unix.POLLIN != 0 {
 			errMsg := eg.Wait()
 			if errMsg != nil {
-				zap.L().Warn("UFFD fd exit error while waiting for goroutines to finish", zap.String("sandbox_id", sandboxId), zap.Error(errMsg), zap.String("node_id", consul.ClientID))
+				zap.L().Warn("UFFD fd exit error while waiting for goroutines to finish", zap.String("sandbox_id", sandboxId), zap.Error(errMsg), zap.String("node_id", nodeID))
 
 				return fmt.Errorf("failed to handle uffd: %w", errMsg)
 			}
@@ -111,20 +121,20 @@ outerLoop:
 			}
 
 			if err == syscall.EAGAIN {
-				zap.L().Debug("uffd: eagain error, going back to polling", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", consul.ClientID), zap.Int("read_bytes", n))
+				zap.L().Debug("uffd: eagain error, going back to polling", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", nodeID), zap.Int("read_bytes", n))
 
 				// Continue polling the fd.
 				continue outerLoop
 			}
 
-			zap.L().Error("uffd: read error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", consul.ClientID))
+			zap.L().Error("uffd: read error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", nodeID))
 
 			return fmt.Errorf("failed to read: %w", err)
 		}
 
 		msg := (*(*constants.UffdMsg)(unsafe.Pointer(&buf[0])))
 		if constants.GetMsgEvent(&msg) != constants.UFFD_EVENT_PAGEFAULT {
-			zap.L().Error("UFFD serve unexpected event type", zap.String("sandbox_id", sandboxId), zap.String("node_id", consul.ClientID), zap.Any("event_type", constants.GetMsgEvent(&msg)))
+			zap.L().Error("UFFD serve unexpected event type", zap.String("sandbox_id", sandboxId), zap.String("node_id", nodeID), zap.Any("event_type", constants.GetMsgEvent(&msg)))
 
 			return ErrUnexpectedEventType
 		}
@@ -136,7 +146,7 @@ outerLoop:
 
 		mapping, err := getMapping(uintptr(addr), mappings)
 		if err != nil {
-			zap.L().Error("UFFD serve get mapping error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", consul.ClientID))
+			zap.L().Error("UFFD serve get mapping error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", nodeID))
 
 			return fmt.Errorf("failed to map: %w", err)
 		}
@@ -147,7 +157,7 @@ outerLoop:
 		eg.Go(func() error {
 			defer func() {
 				if r := recover(); r != nil {
-					zap.L().Error("UFFD serve panic", zap.String("sandbox_id", sandboxId), zap.String("node_id", consul.ClientID), zap.Any("offset", offset), zap.Any("pagesize", pagesize), zap.Any("panic", r))
+					zap.L().Error("UFFD serve panic", zap.String("sandbox_id", sandboxId), zap.String("node_id", nodeID), zap.Any("offset", offset), zap.Any("pagesize", pagesize), zap.Any("panic", r))
 					fmt.Printf("[sandbox %s]: recovered from panic in uffd serve (offset: %d, pagesize: %d): %v\n", sandboxId, offset, pagesize, r)
 				}
 			}()
@@ -157,7 +167,7 @@ outerLoop:
 
 				stop()
 
-				zap.L().Error("UFFD serve slice error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", consul.ClientID))
+				zap.L().Error("UFFD serve slice error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", nodeID))
 
 				return fmt.Errorf("failed to read from source: %w", err)
 			}
@@ -177,7 +187,7 @@ outerLoop:
 				uintptr(unsafe.Pointer(&cpy)),
 			); errno != 0 {
 				if errno == unix.EEXIST {
-					zap.L().Debug("UFFD serve page already mapped", zap.String("sandbox_id", sandboxId), zap.String("node_id", consul.ClientID), zap.Any("offset", offset), zap.Any("pagesize", pagesize))
+					zap.L().Debug("UFFD serve page already mapped", zap.String("sandbox_id", sandboxId), zap.String("node_id", nodeID), zap.Any("offset", offset), zap.Any("pagesize", pagesize))
 
 					// Page is already mapped
 					return nil
@@ -185,7 +195,7 @@ outerLoop:
 
 				stop()
 
-				zap.L().Error("UFFD serve uffdio copy error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", consul.ClientID))
+				zap.L().Error("UFFD serve uffdio copy error", zap.String("sandbox_id", sandboxId), zap.Error(err), zap.String("node_id", nodeID))
 
 				return fmt.Errorf("failed uffdio copy %w", errno)
 			}
diff --git a/packages/orchestrator/internal/sandbox/uffd/serve_other.go b/packages/orchestrator/internal/sandbox/uffd/serve_other.go
new file mode 100644
index 0000000000..6bd13ba967
--- /dev/null
+++ b/packages/orchestrator/internal/sandbox/uffd/serve_other.go
@@ -0,0 +1,23 @@
+//go:build !linux
+// +build !linux
+
+package uffd
+
+import (
+	"errors"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block"
+)
+
+var ErrUnexpectedEventType = errors.New("unexpected event type")
+
+type GuestRegionUffdMapping struct {
+	BaseHostVirtAddr uintptr `json:"base_host_virt_addr"`
+	Size             uintptr `json:"size"`
+	Offset           uintptr `json:"offset"`
+	PageSize         uintptr `json:"page_size_kib"`
+}
+
+func Serve(uffd int, mappings []GuestRegionUffdMapping, src *block.TrackedSliceDevice, fd uintptr, stop func() error, sandboxId string, nodeID string) error {
+	return errors.New("platform does not support UFFD")
+}
diff --git a/packages/orchestrator/internal/server/main.go b/packages/orchestrator/internal/server/main.go
index 5a13abf8ac..edb2c266e1 100644
--- a/packages/orchestrator/internal/server/main.go
+++ b/packages/orchestrator/internal/server/main.go
@@ -21,6 +21,7 @@ import (
 
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/dns"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template"
 	e2bgrpc "github.com/e2b-dev/infra/packages/shared/pkg/grpc"
@@ -39,7 +40,9 @@ type server struct {
 	networkPool   *network.Pool
 	templateCache *template.Cache
 
-	pauseMu sync.Mutex
+	pauseMu    sync.Mutex
+	clientID   string // nomad node id
+	devicePool *nbd.DevicePool
 }
 
 type Service struct {
@@ -54,11 +57,15 @@ type Service struct {
 	}
 }
 
-func New(ctx context.Context, port uint) (*Service, error) {
+func New(ctx context.Context, port uint, clientID string) (*Service, error) {
 	if port > math.MaxUint16 {
 		return nil, fmt.Errorf("%d is larger than maximum possible port %d", port, math.MaxInt16)
 	}
 
+	if clientID == "" {
+		return nil, errors.New("clientID is required")
+	}
+
 	srv := &Service{port: uint16(port)}
 
 	templateCache, err := template.NewCache(ctx)
@@ -66,7 +73,7 @@ func New(ctx context.Context, port uint) (*Service, error) {
 		return nil, fmt.Errorf("failed to create template cache: %w", err)
 	}
 
-	networkPool, err := network.NewPool(ctx, network.NewSlotsPoolSize, network.ReusedSlotsPoolSize)
+	networkPool, err := network.NewPool(ctx, network.NewSlotsPoolSize, network.ReusedSlotsPoolSize, clientID)
 	if err != nil {
 		return nil, fmt.Errorf("failed to create network pool: %w", err)
 	}
@@ -97,12 +104,19 @@ func New(ctx context.Context, port uint) (*Service, error) {
 			),
 		)
 
+		devicePool, err := nbd.NewDevicePool()
+		if err != nil {
+			return nil, fmt.Errorf("failed to create device pool: %w", err)
+		}
+
 		srv.server = &server{
 			tracer:        otel.Tracer(ServiceName),
 			dns:           srv.dns,
 			sandboxes:     smap.New[*sandbox.Sandbox](),
 			networkPool:   networkPool,
 			templateCache: templateCache,
+			clientID:      clientID,
+			devicePool:    devicePool,
 		}
 	}
 
diff --git a/packages/orchestrator/internal/server/sandboxes.go b/packages/orchestrator/internal/server/sandboxes.go
index 5fd12537a4..b553273552 100644
--- a/packages/orchestrator/internal/server/sandboxes.go
+++ b/packages/orchestrator/internal/server/sandboxes.go
@@ -16,7 +16,6 @@ import (
 	"google.golang.org/protobuf/types/known/emptypb"
 	"google.golang.org/protobuf/types/known/timestamppb"
 
-	"github.com/e2b-dev/infra/packages/orchestrator/internal/consul"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build"
 	"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
@@ -42,7 +41,7 @@ func (s *server) Create(ctxConn context.Context, req *orchestrator.SandboxCreate
 		attribute.String("template.id", req.Sandbox.TemplateId),
 		attribute.String("kernel.version", req.Sandbox.KernelVersion),
 		attribute.String("sandbox.id", req.Sandbox.SandboxId),
-		attribute.String("client.id", consul.ClientID),
+		attribute.String("client.id", s.clientID),
 		attribute.String("envd.version", req.Sandbox.EnvdVersion),
 	)
 
@@ -58,6 +57,8 @@ func (s *server) Create(ctxConn context.Context, req *orchestrator.SandboxCreate
 		req.EndTime.AsTime(),
 		req.Sandbox.Snapshot,
 		req.Sandbox.BaseTemplateId,
+		s.clientID,
+		s.devicePool,
 	)
 	if err != nil {
 		zap.L().Error("failed to create sandbox, cleaning up", zap.Error(err))
@@ -88,7 +89,7 @@ func (s *server) Create(ctxConn context.Context, req *orchestrator.SandboxCreate
 	}()
 
 	return &orchestrator.SandboxCreateResponse{
-		ClientId: consul.ClientID,
+		ClientId: s.clientID,
 	}, nil
 }
 
@@ -98,7 +99,7 @@ func (s *server) Update(ctx context.Context, req *orchestrator.SandboxUpdateRequ
 
 	childSpan.SetAttributes(
 		attribute.String("sandbox.id", req.SandboxId),
-		attribute.String("client.id", consul.ClientID),
+		attribute.String("client.id", s.clientID),
 	)
 
 	item, ok := s.sandboxes.Get(req.SandboxId)
@@ -133,7 +134,7 @@ func (s *server) List(ctx context.Context, _ *emptypb.Empty) (*orchestrator.Sand
 
 		sandboxes = append(sandboxes, &orchestrator.RunningSandbox{
 			Config:    sbx.Config,
-			ClientId:  consul.ClientID,
+			ClientId:  s.clientID,
 			StartTime: timestamppb.New(sbx.StartedAt),
 			EndTime:   timestamppb.New(sbx.EndAt),
 		})
@@ -153,7 +154,7 @@ func (s *server) Delete(ctxConn context.Context, in *orchestrator.SandboxDeleteR
 
 	childSpan.SetAttributes(
 		attribute.String("sandbox.id", in.SandboxId),
-		attribute.String("client.id", consul.ClientID),
+		attribute.String("client.id", s.clientID),
 	)
 
 	sbx, ok := s.sandboxes.Get(in.SandboxId)
diff --git a/packages/orchestrator/internal/server/sandboxes_test.go b/packages/orchestrator/internal/server/sandboxes_test.go
new file mode 100644
index 0000000000..d7e72c136e
--- /dev/null
+++ b/packages/orchestrator/internal/server/sandboxes_test.go
@@ -0,0 +1,82 @@
+package server
+
+import (
+	"context"
+	"reflect"
+	"testing"
+	"time"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
+	"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
+	"github.com/e2b-dev/infra/packages/shared/pkg/smap"
+	"go.opentelemetry.io/otel/trace/noop"
+	"google.golang.org/protobuf/types/known/emptypb"
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+var (
+	startTime = time.Now()
+	endTime   = time.Now().Add(time.Hour)
+)
+
+func Test_server_List(t *testing.T) {
+	type args struct {
+		ctx context.Context
+		in1 *emptypb.Empty
+	}
+	tests := []struct {
+		name    string
+		args    args
+		want    *orchestrator.SandboxListResponse
+		wantErr bool
+		data    []*sandbox.Sandbox
+	}{
+		{
+			name: "should return all sandboxes",
+
+			args: args{
+				ctx: context.Background(),
+				in1: &emptypb.Empty{},
+			},
+			data: []*sandbox.Sandbox{
+				{
+					Config: &orchestrator.SandboxConfig{
+						TemplateId: "template-id",
+					},
+					StartedAt: startTime,
+					EndAt:     endTime,
+				},
+			},
+			want: &orchestrator.SandboxListResponse{
+				Sandboxes: []*orchestrator.RunningSandbox{
+					{
+						Config: &orchestrator.SandboxConfig{TemplateId: "template-id"},
+						// ClientId:  "client-id",
+						StartTime: timestamppb.New(startTime),
+						EndTime:   timestamppb.New(endTime),
+					},
+				},
+			},
+			wantErr: false,
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			s := &server{
+				sandboxes: smap.New[*sandbox.Sandbox](),
+				tracer:    noop.NewTracerProvider().Tracer(""),
+			}
+			for _, sbx := range tt.data {
+				s.sandboxes.Insert(sbx.Config.SandboxId, sbx)
+			}
+			got, err := s.List(tt.args.ctx, tt.args.in1)
+			if (err != nil) != tt.wantErr {
+				t.Errorf("server.List() error = %v, wantErr %v", err, tt.wantErr)
+				return
+			}
+			if !reflect.DeepEqual(got, tt.want) {
+				t.Errorf("server.List() = %v, want %v", got, tt.want)
+			}
+		})
+	}
+}
diff --git a/packages/orchestrator/main.go b/packages/orchestrator/main.go
index e613ef7dcc..400fe5375d 100644
--- a/packages/orchestrator/main.go
+++ b/packages/orchestrator/main.go
@@ -15,6 +15,7 @@ import (
 	"go.uber.org/zap"
 	"go.uber.org/zap/zapcore"
 
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/consul"
 	"github.com/e2b-dev/infra/packages/orchestrator/internal/server"
 	"github.com/e2b-dev/infra/packages/shared/pkg/env"
 	"github.com/e2b-dev/infra/packages/shared/pkg/logger"
@@ -95,7 +96,9 @@ func main() {
 
 	log.Println("Starting orchestrator", "commit", commitSHA)
 
-	srv, err := server.New(ctx, port)
+	clientID := consul.GetClientID()
+
+	srv, err := server.New(ctx, port, clientID)
 	if err != nil {
 		zap.L().Fatal("failed to create server", zap.Error(err))
 	}


Reviews:
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T03:20:58Z
user: login: dobrac
state: DISMISSED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T09:20:57Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T17:04:06Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T17:08:08Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T17:12:01Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T17:15:34Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T17:18:44Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T17:19:58Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T17:23:29Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T18:05:35Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T18:05:54Z
user: login: jakubno
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-07T18:07:26Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T18:14:20Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T18:15:14Z
user: login: jakubno
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-07T19:02:41Z
user: login: r33drichards
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T19:03:54Z
user: login: dobrac
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-07T19:55:37Z
user: login: ValentaTomas
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-08T00:21:40Z
user: login: ValentaTomas
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-08T00:30:00Z

Review comments:
diff_hunk: @@ -57,9 +57,7 @@ type DevicePool struct {
 	slotCounter metric.Int64UpDownCounter
 }
 
-var Pool *DevicePool
-
-func init() {
+func MustGetDevicePool() *DevicePool {
path: packages/orchestrator/internal/sandbox/nbd/pool.go
user: login: r33drichards
body: todo: make sure this is called with sync.OnceValue
created_at: 2025-03-07T03:20:57Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,43 @@
+//go:build !linux
+// +build !linux
+
+package fc
+
+import (
+	"context"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template"
+)
+
+type apiClient struct {
+}
+
+func newApiClient(socketPath string) *apiClient {
+	return nil
+}
+
+// internal/sandbox/fc/process.go:260:17: p.client.loadSnapshot undefined (type *apiClient has no field or method loadSnapshot)
+// internal/sandbox/fc/process.go:272:17: p.client.resumeVM undefined (type *apiClient has no field or method resumeVM)
+// internal/sandbox/fc/process.go:279:17: p.client.setMmds undefined (type *apiClient has no field or method setMmds)
+// internal/sandbox/fc/process.go:320:18: p.client.pauseVM undefined (type *apiClient has no field or method pauseVM)
+// internal/sandbox/fc/process.go:328:18: p.client.createSnapshot undefined (type *apiClient has no field or method createSnapshot)
path: packages/orchestrator/internal/sandbox/fc/client_other.go
user: login: dobrac
body: does this have any meaning?
created_at: 2025-03-07T09:05:52Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: dobrac
body: could these vars be passed from the top -> down? I'm just thinking that right now the execution might fail with panic at random runtime of the code - which is not ideal
created_at: 2025-03-07T09:06:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
path: packages/api/internal/handlers/sandbox_linux.go
user: login: dobrac
body: is this file really linux-compilation specific? Maybe we could abstract it a bit better
created_at: 2025-03-07T09:08:44Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,6 @@
+//go:build linux
path: packages/orchestrator/internal/sandbox/fc/client_linux.go
user: login: dobrac
body: is fc linux specific for compilation?
created_at: 2025-03-07T09:09:32Z
author_association: CONTRIBUTOR
diff_hunk: @@ -57,9 +57,7 @@ type DevicePool struct {
 	slotCounter metric.Int64UpDownCounter
 }
 
-var Pool *DevicePool
-
-func init() {
+func MustGetDevicePool() *DevicePool {
path: packages/orchestrator/internal/sandbox/nbd/pool.go
user: login: dobrac
body: I think better abstraction would be nicer + I think this file is linux specific (""/sys/module/nbd/parameters/nbds_max")
created_at: 2025-03-07T09:13:15Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
path: packages/orchestrator/internal/sandbox/sandbox_linux.go
user: login: dobrac
body: I don't think this file should be linux specific too
created_at: 2025-03-07T09:14:46Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,82 @@
+package server
+
+import (
+	"context"
+	"reflect"
+	"testing"
+	"time"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
+	"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
+	"github.com/e2b-dev/infra/packages/shared/pkg/smap"
+	"go.opentelemetry.io/otel/trace/noop"
+	"google.golang.org/protobuf/types/known/emptypb"
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+var (
+	startTime = time.Now()
+	endTime   = time.Now().Add(time.Hour)
+)
+
+func Test_server_List(t *testing.T) {
path: packages/orchestrator/internal/server/sandboxes_test.go
user: login: dobrac
body: not sure how this test is helpful, but I suppose it shows at least it builds
created_at: 2025-03-07T09:20:54Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,43 @@
+//go:build !linux
+// +build !linux
+
+package fc
+
+import (
+	"context"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template"
+)
+
+type apiClient struct {
+}
+
+func newApiClient(socketPath string) *apiClient {
+	return nil
+}
+
+// internal/sandbox/fc/process.go:260:17: p.client.loadSnapshot undefined (type *apiClient has no field or method loadSnapshot)
+// internal/sandbox/fc/process.go:272:17: p.client.resumeVM undefined (type *apiClient has no field or method resumeVM)
+// internal/sandbox/fc/process.go:279:17: p.client.setMmds undefined (type *apiClient has no field or method setMmds)
+// internal/sandbox/fc/process.go:320:18: p.client.pauseVM undefined (type *apiClient has no field or method pauseVM)
+// internal/sandbox/fc/process.go:328:18: p.client.createSnapshot undefined (type *apiClient has no field or method createSnapshot)
path: packages/orchestrator/internal/sandbox/fc/client_other.go
user: login: r33drichards
body: nope! this was just a todo list
created_at: 2025-03-07T17:04:05Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
path: packages/api/internal/handlers/sandbox_linux.go
user: login: r33drichards
body: looks like its not!
```
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗ go test -v ./...                                                                           ~/infra/packages/orchestrator
?       github.com/e2b-dev/infra/packages/orchestrator  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-data [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-header       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-snapshot        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/simulate-headers-merge       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/consul  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/dns     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/fc      [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/rootfs  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/socket  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/stats   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/uffd    [no test files]
=== RUN   Test_server_List
=== RUN   Test_server_List/should_return_all_sandboxes
--- PASS: Test_server_List (0.00s)
    --- PASS: Test_server_List/should_return_all_sandboxes (0.00s)
PASS
ok      github.com/e2b-dev/infra/packages/orchestrator/internal/server  (cached)
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗                                                                                            ~/infra/packages/orchestrator
```
created_at: 2025-03-07T17:08:07Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: r33drichards
body: it does get passed top -> down [here](https://github.com/e2b-dev/infra/blob/d8c246110616250b3f59a2b18cbda38f81948412/packages/orchestrator/internal/server/main.go#L108) this code also make sure its not initialized as a global variable and panics at time that is inconvienient. 
created_at: 2025-03-07T17:12:00Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,6 @@
+//go:build linux
path: packages/orchestrator/internal/sandbox/fc/client_linux.go
user: login: r33drichards
body: when I remove the build flags for linux in this file and run 
```
 go test -v ./...                                                                           ~/infra/packages/orchestrator
github.com/containernetworking/plugins/pkg/ns: build constraints exclude all Go files in /Users/f/go/pkg/mod/github.com/containernetworking/plugins@v1.6.0/pkg/ns
?       github.com/e2b-dev/infra/packages/orchestrator  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-data [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-header       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-snapshot        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/simulate-headers-merge       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/consul  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/dns     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build   [no test files]
FAIL    github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/fc [build failed]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/socket  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/rootfs  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/stats   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/uffd    [no test files]
=== RUN   Test_server_List
=== RUN   Test_server_List/should_return_all_sandboxes
--- PASS: Test_server_List (0.00s)
    --- PASS: Test_server_List/should_return_all_sandboxes (0.00s)
PASS
ok      github.com/e2b-dev/infra/packages/orchestrator/internal/server  (cached)
FAIL
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗                                                                                            ~/infra/packages/orchestrator
```

i get the error `github.com/containernetworking/plugins/pkg/ns: build constraints exclude all Go files in /Users/f/go/pkg/mod/github.com/containernetworking/plugins@v1.6.0/pkg/ns`
created_at: 2025-03-07T17:15:33Z
author_association: CONTRIBUTOR
diff_hunk: @@ -57,9 +57,7 @@ type DevicePool struct {
 	slotCounter metric.Int64UpDownCounter
 }
 
-var Pool *DevicePool
-
-func init() {
+func MustGetDevicePool() *DevicePool {
path: packages/orchestrator/internal/sandbox/nbd/pool.go
user: login: r33drichards
body: I'm just trying to preserve current functionality without breaking anything for this feature but yea i agree. At a minimum i think it makes sense to use sync.OnceValue but i'm not trying to introduce to many potentially breaking changes if possible
created_at: 2025-03-07T17:18:43Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
path: packages/orchestrator/internal/sandbox/sandbox_linux.go
user: login: r33drichards
body: when i remove the linux build flags and run 
```
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗ go test -v ./...                                                                           ~/infra/packages/orchestrator
# github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox
internal/sandbox/sandbox.go:465:50: undefined: unix.BLKFLSBUF
FAIL    github.com/e2b-dev/infra/packages/orchestrator [build failed]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-data [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-header       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-nbd     [no test files]
FAIL    github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-sandbox [build failed]
FAIL    github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-snapshot [build failed]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/simulate-headers-merge       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/consul  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/dns     [no test files]
FAIL    github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox [build failed]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/fc      [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/rootfs  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/socket  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/stats   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/uffd    [no test files]
FAIL    github.com/e2b-dev/infra/packages/orchestrator/internal/server [build failed]
FAIL
```

i get the error `internal/sandbox/sandbox.go:465:50: undefined: unix.BLKFLSBUF`
created_at: 2025-03-07T17:19:57Z
author_association: CONTRIBUTOR
diff_hunk: @@ -0,0 +1,82 @@
+package server
+
+import (
+	"context"
+	"reflect"
+	"testing"
+	"time"
+
+	"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox"
+	"github.com/e2b-dev/infra/packages/shared/pkg/grpc/orchestrator"
+	"github.com/e2b-dev/infra/packages/shared/pkg/smap"
+	"go.opentelemetry.io/otel/trace/noop"
+	"google.golang.org/protobuf/types/known/emptypb"
+	"google.golang.org/protobuf/types/known/timestamppb"
+)
+
+var (
+	startTime = time.Now()
+	endTime   = time.Now().Add(time.Hour)
+)
+
+func Test_server_List(t *testing.T) {
path: packages/orchestrator/internal/server/sandboxes_test.go
user: login: r33drichards
body: ```

	sandboxes := make([]*orchestrator.RunningSandbox, 0, len(items))

	for _, sbx := range items {
		if sbx == nil {
			continue
		}

		if sbx.Config == nil {
			continue
		}

		sandboxes = append(sandboxes, &orchestrator.RunningSandbox{
			Config:    sbx.Config,
			ClientId:  s.clientID,
			StartTime: timestamppb.New(sbx.StartedAt),
			EndTime:   timestamppb.New(sbx.EndAt),
		})
	}

	return &orchestrator.SandboxListResponse{
		Sandboxes: sandboxes
    }, nil
```

this is the operations that are under test, which yea, i get is pretty easy to eyeball, but the only way to true verify something like that is to execute the code. a test automates that for a reviewer and will also serve as a canary for if we ever refactor it. I could expand this test case to handle things like nil sbx or sbx.Config being nil to cover more buisiness logic cases but as you said, this exists mostly to prove the refactor can execute tests locally at all. 
created_at: 2025-03-07T17:23:27Z
author_association: CONTRIBUTOR
diff_hunk: @@ -57,9 +57,7 @@ type DevicePool struct {
 	slotCounter metric.Int64UpDownCounter
 }
 
-var Pool *DevicePool
-
-func init() {
+func MustGetDevicePool() *DevicePool {
path: packages/orchestrator/internal/sandbox/nbd/pool.go
user: login: r33drichards
body: the more i think about it the more i think it makes sense to add a compile flag here
created_at: 2025-03-07T18:05:35Z
author_association: CONTRIBUTOR
diff_hunk: @@ -57,9 +57,7 @@ type DevicePool struct {
 	slotCounter metric.Int64UpDownCounter
 }
 
-var Pool *DevicePool
-
-func init() {
+func MustGetDevicePool() *DevicePool {
path: packages/orchestrator/internal/sandbox/nbd/pool.go
user: login: r33drichards
body: it would be a more "honest" design
created_at: 2025-03-07T18:05:54Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: jakubno
body: Agree with @dobrac, this kinda destroys the whole idea about requiring environment variable
created_at: 2025-03-07T18:07:26Z
author_association: MEMBER
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: r33drichards
body: if the environment variable is not set it will be detected when orchestrator starts and error, this change only affects the fact that its not set as a global variable, failing when executing tests
created_at: 2025-03-07T18:14:20Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: r33drichards
body: ```
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗ go build                                                                                   ~/infra/packages/orchestrator
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ls                                                                                           ~/infra/packages/orchestrator
Dockerfile         README.md          cmd                go.sum             main.go            orchestrator.proto
Makefile           bin                go.mod             internal           orchestrator       upload.sh
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) cd bin                                                                                       ~/infra/packages/orchestrator
➜  bin git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ls                                                                                                ~/infra/packages/orchestrator/bin
orchestrator
➜  bin git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ./orchestrator                                                                                    ~/infra/packages/orchestrator/bin
panic: Required environment variable "NODE_ID" (Nomad ID of the instance node) is not set. Please set it to a non-empty value.

goroutine 1 [running]:
github.com/e2b-dev/infra/packages/shared/pkg/utils.RequiredEnv({0x1036969d5, 0x7}, {0x1036b3995, 0x1d})
        /Users/f/infra/packages/shared/pkg/utils/env.go:16 +0x1a8
github.com/e2b-dev/infra/packages/orchestrator/internal/consul.init()
        /Users/f/infra/packages/orchestrator/internal/consul/node.go:10 +0x34
        ```
created_at: 2025-03-07T18:15:14Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: jakubno
body: This is safety feature, now it's checked during start, but then somebody comes, this isn't really needed to be on the struct and can be read directly. is it problem to set the env variable?
created_at: 2025-03-07T19:02:41Z
author_association: MEMBER
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: r33drichards
body: not sure what you mean by this
created_at: 2025-03-07T19:03:53Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,3 +1,6 @@
+//go:build linux
+// +build linux
path: packages/orchestrator/internal/sandbox/sandbox_linux.go
user: login: dobrac
body: I think it would make sense to extract this one call (or that part) out of this file and then it shouldn't be linux specific anymore
created_at: 2025-03-07T19:55:37Z
author_association: CONTRIBUTOR
diff_hunk: @@ -1,13 +1,20 @@
 package consul
 
 import (
+	"sync"
+
 	"github.com/e2b-dev/infra/packages/shared/pkg/utils"
 )
 
 const shortNodeIDLength = 8
 
 var (
-	nodeID = utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+	getNodeID = sync.OnceValue(func() string {
+		return utils.RequiredEnv("NODE_ID", "Nomad ID of the instance node")
+
+	})
 	// Node ID must be at least 8 characters long.
-	ClientID = nodeID[:shortNodeIDLength]
+	GetClientID = sync.OnceValue(func() string {
+		return getNodeID()[:shortNodeIDLength]
+	})
path: packages/orchestrator/internal/consul/node.go
user: login: ValentaTomas
body: We moved the getting of env var to the main and just pass it down now.
created_at: 2025-03-08T00:21:40Z
author_association: MEMBER

PR comments:
user: login: linear[bot]
created_at: 2025-03-06T20:13:20Z
body: <p><a href="https://linear.app/e2b/issue/E2B-1718/refactor-codebase-to-support-platform-compile-flags">E2B-1718 refactor codebase to support platform compile flags</a></p>
author_association: NONE
user: login: r33drichards
created_at: 2025-03-06T23:02:42Z
body: ```
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗ go test -timeout 20s -run ^Test_server_List$ github.com/e2b-dev/infra/packages/orchestrator/internal/server
ok      github.com/e2b-dev/infra/packages/orchestrator/internal/server  (cached)
```
author_association: CONTRIBUTOR
user: login: r33drichards
created_at: 2025-03-06T23:28:10Z
body: ```
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗ pwd                                                                                        ~/infra/packages/orchestrator
/Users/f/infra/packages/orchestrator
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗ go test -v ./...                                                                           ~/infra/packages/orchestrator
github.com/containernetworking/plugins/pkg/ns: build constraints exclude all Go files in /Users/f/go/pkg/mod/github.com/containernetworking/plugins@v1.6.0/pkg/ns
?       github.com/e2b-dev/infra/packages/orchestrator  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-data [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-header       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-snapshot        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/simulate-headers-merge       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/consul  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/dns     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build   [no test files]
FAIL    github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/fc [build failed]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/rootfs  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/socket  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/stats   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/uffd    [no test files]
=== RUN   Test_server_List
=== RUN   Test_server_List/should_return_all_sandboxes
--- PASS: Test_server_List (0.00s)
    --- PASS: Test_server_List/should_return_all_sandboxes (0.00s)
PASS
ok      github.com/e2b-dev/infra/packages/orchestrator/internal/server  (cached)
FAIL
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) ✗    
```
author_association: CONTRIBUTOR
user: login: r33drichards
created_at: 2025-03-06T23:35:30Z
body: tests for orchestrator now run locally! 

```
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) pwd                                                                                          ~/infra/packages/orchestrator
/Users/f/infra/packages/orchestrator
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718) go test -v ./...                                                                             ~/infra/packages/orchestrator
?       github.com/e2b-dev/infra/packages/orchestrator  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-data [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/inspect-header       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/mock-snapshot        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/cmd/simulate-headers-merge       [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/consul  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/dns     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/block   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/build   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/fc      [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/nbd     [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/network [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/rootfs  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/socket  [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/stats   [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/template        [no test files]
?       github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/uffd    [no test files]
=== RUN   Test_server_List
=== RUN   Test_server_List/should_return_all_sandboxes
--- PASS: Test_server_List (0.00s)
    --- PASS: Test_server_List/should_return_all_sandboxes (0.00s)
PASS
ok      github.com/e2b-dev/infra/packages/orchestrator/internal/server  (cached)
➜  orchestrator git:(refactor-codebase-to-support-platform-compile-flags-e2b-1718)     ```
author_association: CONTRIBUTOR
user: login: r33drichards
created_at: 2025-03-07T18:20:25Z
body: deployed this branch to my cluster and am able to create a sandbox w/o errors 
```
npx @e2b/cli sandbox spawn base
Terminal connecting to template base with sandbox ID igryzhg2zodfa0omx5sey-939d892f
user@6fd6bcb769c7:~$ 
```
author_association: CONTRIBUTOR