@alineo-labs/sandbox 0.3.0 → 0.4.0
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/dist/index.d.mts +8 -0
- package/dist/index.mjs +22 -3
- package/package.json +4 -4
package/dist/index.d.mts
CHANGED
|
@@ -409,6 +409,14 @@ declare class Sandbox {
|
|
|
409
409
|
}, runId?: string, opts?: {
|
|
410
410
|
networkPolicy?: NetworkPolicy$1;
|
|
411
411
|
credentialProxy?: boolean;
|
|
412
|
+
/**
|
|
413
|
+
* Environment for the restored sandbox — normally omitted (a snapshot already carries
|
|
414
|
+
* its container env). Use it only for `OPENSANDBOX_EGRESS_*` sidecar vars, which are
|
|
415
|
+
* process-scoped and must be re-supplied on every restore (the sidecar is not
|
|
416
|
+
* snapshotted): the server routes those to the sidecar and drops them from the
|
|
417
|
+
* container.
|
|
418
|
+
*/
|
|
419
|
+
env?: Record<string, string>;
|
|
412
420
|
/** Resource scope for the restored sandbox — see `SandboxOptions.resourceId`. Unlike
|
|
413
421
|
* `resume()`, `restoreSnapshot()` has no prior ledger session of its own to inherit
|
|
414
422
|
* from (the snapshot may have come from anywhere), so this must be passed explicitly. */
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { BashSession, CommandError, ExecConnectionError, LedgerEvent, LedgerEvent as LedgerEvent$1, SandboxError, SandboxHandle, SandboxHandle as SandboxHandle$1, SandboxStatus, StepTimeoutError, reconstructBoundCredentials, resolveBoundCredential } from "@alineo-labs/core";
|
|
2
|
-
import { CodeLanguage, ControlClient, SandboxState, SnapshotState } from "@alineo-labs/opensandbox";
|
|
1
|
+
import { BashSession, CommandError, ExecConnectionError, LedgerEvent, LedgerEvent as LedgerEvent$1, SandboxError, SandboxHandle, SandboxHandle as SandboxHandle$1, SandboxStatus, StepTimeoutError, reconstructBoundCredentials, reconstructEgressRules, resolveBoundCredential } from "@alineo-labs/core";
|
|
2
|
+
import { CodeLanguage, ControlClient, SandboxState, SnapshotState, isValidEgressTarget } from "@alineo-labs/opensandbox";
|
|
3
3
|
import { OpenSandboxCredentialBroker, OpenSandboxCredentialBroker as OpenSandboxCredentialBroker$1 } from "@alineo-labs/vault";
|
|
4
4
|
//#region src/types.ts
|
|
5
5
|
/**
|
|
@@ -83,6 +83,14 @@ var Environment = class {
|
|
|
83
83
|
//#endregion
|
|
84
84
|
//#region src/client.ts
|
|
85
85
|
/**
|
|
86
|
+
* Reject a `networkPolicy` with a malformed `target` before it reaches the server — a fast
|
|
87
|
+
* local error instead of a round-trip. `undefined` policies pass through untouched.
|
|
88
|
+
*/
|
|
89
|
+
function assertValidNetworkPolicy(policy) {
|
|
90
|
+
if (!policy) return;
|
|
91
|
+
for (const rule of policy.egress ?? []) if (!isValidEgressTarget(rule.target)) throw new SandboxClientError(`Invalid networkPolicy egress target ${JSON.stringify(rule.target)} — expected an FQDN, a "*."-prefixed wildcard domain, a bare IP address, or a CIDR block.`, 400);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
86
94
|
* Main entry point for the sandbox client. Manages sandbox lifecycle and session history.
|
|
87
95
|
*
|
|
88
96
|
* @example
|
|
@@ -153,6 +161,7 @@ var Sandbox = class {
|
|
|
153
161
|
* ```
|
|
154
162
|
*/
|
|
155
163
|
async sandbox(opts) {
|
|
164
|
+
assertValidNetworkPolicy(opts.networkPolicy);
|
|
156
165
|
await this._ensureConnected();
|
|
157
166
|
await this._acquireSlot();
|
|
158
167
|
const image = typeof opts.image === "string" ? { uri: opts.image } : opts.image;
|
|
@@ -260,8 +269,16 @@ var Sandbox = class {
|
|
|
260
269
|
const runId = createdPayload?.runId ?? crypto.randomUUID();
|
|
261
270
|
const resourceId = createdPayload?.resourceId;
|
|
262
271
|
const teamId = createdPayload?.teamId;
|
|
263
|
-
const
|
|
272
|
+
const originalNetworkPolicy = createdPayload?.networkPolicy;
|
|
264
273
|
const credentialProxy = createdPayload?.credentialProxy;
|
|
274
|
+
const replayedEgress = originalNetworkPolicy ? reconstructEgressRules(entries) : {
|
|
275
|
+
apply: [],
|
|
276
|
+
remove: []
|
|
277
|
+
};
|
|
278
|
+
const networkPolicy = originalNetworkPolicy ? {
|
|
279
|
+
...originalNetworkPolicy,
|
|
280
|
+
egress: [...replayedEgress.apply, ...(originalNetworkPolicy.egress ?? []).filter((r) => !replayedEgress.apply.some((rr) => rr.target === r.target) && !replayedEgress.remove.includes(r.target))]
|
|
281
|
+
} : void 0;
|
|
265
282
|
const boundCredentials = reconstructBoundCredentials(entries);
|
|
266
283
|
const replayCache = /* @__PURE__ */ new Map();
|
|
267
284
|
const pendingStdout = /* @__PURE__ */ new Map();
|
|
@@ -421,12 +438,14 @@ var Sandbox = class {
|
|
|
421
438
|
* ```
|
|
422
439
|
*/
|
|
423
440
|
async restoreSnapshot(snapshotId, name, resources, runId, opts) {
|
|
441
|
+
assertValidNetworkPolicy(opts?.networkPolicy);
|
|
424
442
|
await this._ensureConnected();
|
|
425
443
|
await this._acquireSlot();
|
|
426
444
|
try {
|
|
427
445
|
const finalRunId = runId ?? crypto.randomUUID();
|
|
428
446
|
const newId = (await this._control.createSandbox({
|
|
429
447
|
snapshotId,
|
|
448
|
+
env: opts?.env,
|
|
430
449
|
resourceLimits: resources,
|
|
431
450
|
metadata: { runId: finalRunId },
|
|
432
451
|
networkPolicy: opts?.networkPolicy,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alineo-labs/sandbox",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
"test:watch": "vitest"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@alineo-labs/core": "0.
|
|
33
|
-
"@alineo-labs/opensandbox": "0.
|
|
34
|
-
"@alineo-labs/vault": "0.
|
|
32
|
+
"@alineo-labs/core": "0.4.0",
|
|
33
|
+
"@alineo-labs/opensandbox": "0.3.0",
|
|
34
|
+
"@alineo-labs/vault": "0.3.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"bun-types": "1.3.14",
|