@luxorai/sandbox
Version:
TypeScript SDK for Luxor Sandbox: cloud sandboxes (microVMs) for AI agents on Luxor Agent Cloud
40 lines • 1.76 kB
JavaScript
import { create } from "@bufbuild/protobuf";
import { timestampDate } from "@bufbuild/protobuf/wkt";
import { SessionEgressPolicySchema, } from "./internal/proto/tenki/sandbox/v1/sandbox_pb.js";
import { egressHttpRuleToProto, egressPolicyFromProto } from "./session.js";
export function egressPolicySpecToProto(spec) {
return create(SessionEgressPolicySchema, {
allowDomains: [...(spec.allowDomains ?? [])],
allowCidrs: [...(spec.allowCidrs ?? [])],
interceptHttps: spec.interceptHttps ?? false,
allowedPorts: [...(spec.allowedPorts ?? [])],
publicEgress: spec.publicEgress,
httpRules: (spec.httpRules ?? []).map(egressHttpRuleToProto),
});
}
export function egressPolicyFromMessage(policy) {
if (!policy)
throw new Error("Missing egress policy");
return {
id: policy.id,
workspaceId: policy.workspaceId,
name: policy.name,
revision: policy.revision,
egress: egressPolicyFromProto(policy.egress),
activeSessionCount: policy.activeSessionCount,
createdAt: policy.createdAt && timestampDate(policy.createdAt),
updatedAt: policy.updatedAt && timestampDate(policy.updatedAt),
deletedAt: policy.deletedAt && timestampDate(policy.deletedAt),
};
}
export function workspaceScope(options) {
return options?.workspaceId?.trim() || undefined;
}
export function publicEgressAcknowledged(requested, actual) {
if (requested === undefined)
return true;
return (actual !== undefined &&
actual.tcpPorts.every((port) => (requested.tcpPorts ?? []).includes(port)) &&
actual.udpPorts.every((port) => (requested.udpPorts ?? []).includes(port)));
}
//# sourceMappingURL=egress-policies.js.map