@cloudflare/sandbox 0.12.3 → 0.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -98,6 +98,26 @@ export default {
98
98
  };
99
99
  ```
100
100
 
101
+ ## Sandbox options
102
+
103
+ Pass options as the third argument to `getSandbox()` to configure sandbox
104
+ lifetime and container startup metadata:
105
+
106
+ ```ts
107
+ const sandbox = getSandbox(env.Sandbox, 'tenant-workspace', {
108
+ sleepAfter: '30m',
109
+ labels: {
110
+ tenantId: 'tenant_123',
111
+ workload: 'code-workspace'
112
+ }
113
+ });
114
+ ```
115
+
116
+ Container labels are attached to the underlying Cloudflare Container for
117
+ analytics and observability. Labels are applied when the container starts; if
118
+ labels are changed while a container is already running, the new labels apply
119
+ the next time the container starts.
120
+
101
121
  ## Quick tunnels
102
122
 
103
123
  `sandbox.tunnels.get(port)` exposes a service running inside the
@@ -49,6 +49,8 @@ interface BridgeEnv {
49
49
  SANDBOX_API_KEY?: string;
50
50
  WARM_POOL_TARGET?: string;
51
51
  WARM_POOL_REFRESH_INTERVAL?: string;
52
+ WARM_POOL_MAX_INSTANCES?: string;
53
+ WARM_POOL_SCALE_BATCH_SIZE?: string;
52
54
  [key: string]: unknown;
53
55
  }
54
56
  //#endregion
@@ -75,6 +77,20 @@ interface WarmPoolConfig {
75
77
  warmTarget?: number;
76
78
  /** How often to check and replenish warm containers (ms). @default 10000 */
77
79
  refreshInterval?: number;
80
+ /**
81
+ * Operator-declared max_instances ceiling, mirroring
82
+ * `containers[].max_instances` in wrangler.jsonc. Seeds the pool's capacity
83
+ * math so it never blindly attempts doomed starts. 0/undefined = auto-learn
84
+ * the ceiling reactively from platform errors (legacy behaviour).
85
+ * @default 0
86
+ */
87
+ maxInstances?: number;
88
+ /**
89
+ * Number of containers to start in parallel per scale-up batch. Higher
90
+ * values fill the pool faster but risk the platform throttling a cold-start
91
+ * stampede. Clamped to [1, MAX_BATCH_SIZE]. @default 5
92
+ */
93
+ scaleBatchSize?: number;
78
94
  }
79
95
  interface PoolStats {
80
96
  /** Number of warm (unassigned) containers ready for use */
@@ -109,6 +125,13 @@ declare class WarmPool extends DurableObject<WarmPoolEnv> {
109
125
  private knownMaxInstances;
110
126
  private capacityExhausted;
111
127
  private initialized;
128
+ /** Guards against overlapping eager refills triggered by concurrent pops. */
129
+ private refillInFlight;
130
+ /**
131
+ * The currently in-flight eager refill, or null. Exposed for tests to await
132
+ * the otherwise fire-and-forget refill deterministically.
133
+ */
134
+ private refillPromise;
112
135
  /**
113
136
  * Get a container UUID for the given sandbox ID.
114
137
  * - If this ID already has an assigned container that's still running, return it.
@@ -139,6 +162,13 @@ declare class WarmPool extends DurableObject<WarmPoolEnv> {
139
162
  * Does not affect containers that are assigned to sandbox IDs.
140
163
  */
141
164
  shutdownPrewarmed(): Promise<void>;
165
+ /**
166
+ * Kick a non-blocking refill toward warmTarget. Debounced via refillInFlight
167
+ * so a burst of concurrent pops triggers at most one adjustPool sweep at a
168
+ * time; capacity is respected because adjustPool clamps to remainingCapacity.
169
+ * Errors are swallowed so a failed refill never rejects the triggering call.
170
+ */
171
+ private requestRefill;
142
172
  alarm(): Promise<void>;
143
173
  private init;
144
174
  private persist;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/bridge/types.ts","../../src/bridge/helpers.ts","../../src/bridge/warm-pool.ts","../../src/bridge/index.ts"],"sourcesContent":[],"mappings":";;;;;;;AA6DgB,UAvCC,YAAA,CAuCD;EAEP;;;AAaT;;;;ICJgB,OAAA,CAAA,EAAU,MAAA;IAyBV;;;;AC7EhB;AAOA;AAWC;AA6CD;EAA4C,cAAA,CAAA,EAAA,MAAA;EA2BH;;;;;EAiFf,WAAA,CAAA,EAAA,MAAA;;;;;;;;UFzIT,cAAA;EGgCD,KAAA,EAAA,OAAM,EH9BT,OG8BS,EAAA,GAAA,EAAA,GAAA,EAAA,GAAA,EH5Bb,gBG4Ba,CAAA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