@lizard-build/sdk 1.0.0 → 1.0.2

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 CHANGED
@@ -1766,6 +1766,8 @@ interface SandboxInfo {
1766
1766
  size?: 'small' | 'medium' | 'large' | null;
1767
1767
  /** Flat hourly price in USD for `size`, billed per second while running; may be `null` when billed by measured usage. */
1768
1768
  pricePerHour?: number | null;
1769
+ /** `false` when the sandbox was created with `internetAccess: false`; absent from older servers. */
1770
+ internetAccess?: boolean;
1769
1771
  cpus?: number;
1770
1772
  memoryMb?: number;
1771
1773
  metadata?: Record<string, string>;
@@ -1820,6 +1822,12 @@ interface SandboxOpts extends ConnectionOpts {
1820
1822
  metadata?: Record<string, string>;
1821
1823
  /** Environment variables set in the sandbox, visible to every command it runs. */
1822
1824
  envs?: Record<string, string>;
1825
+ /**
1826
+ * `false`: no internet for the sandbox's whole life, its resumes and forks included (no
1827
+ * outbound TCP, UDP, DNS or ping); commands, files and exposed ports still work. Set at
1828
+ * create only. Default `true`. Not available with a container volume or snapshot.
1829
+ */
1830
+ internetAccess?: boolean;
1823
1831
  timeoutMs?: number;
1824
1832
  /**
1825
1833
  * Region to run the sandbox in, e.g. `'us-east-1'`.
@@ -1829,7 +1837,7 @@ interface SandboxOpts extends ConnectionOpts {
1829
1837
  * is not in is rejected with a 400 rather than silently moved — that combination
1830
1838
  * cannot be satisfied.
1831
1839
  *
1832
- * Defaults to the platform's default sandbox region.
1840
+ * Defaults to `'us-east-1'`, or to the volume's or snapshot's region when one is given.
1833
1841
  */
1834
1842
  region?: string;
1835
1843
  /** Attach a persistent volume by id, mounted at `/workspace`. */
package/dist/index.d.ts CHANGED
@@ -1766,6 +1766,8 @@ interface SandboxInfo {
1766
1766
  size?: 'small' | 'medium' | 'large' | null;
1767
1767
  /** Flat hourly price in USD for `size`, billed per second while running; may be `null` when billed by measured usage. */
1768
1768
  pricePerHour?: number | null;
1769
+ /** `false` when the sandbox was created with `internetAccess: false`; absent from older servers. */
1770
+ internetAccess?: boolean;
1769
1771
  cpus?: number;
1770
1772
  memoryMb?: number;
1771
1773
  metadata?: Record<string, string>;
@@ -1820,6 +1822,12 @@ interface SandboxOpts extends ConnectionOpts {
1820
1822
  metadata?: Record<string, string>;
1821
1823
  /** Environment variables set in the sandbox, visible to every command it runs. */
1822
1824
  envs?: Record<string, string>;
1825
+ /**
1826
+ * `false`: no internet for the sandbox's whole life, its resumes and forks included (no
1827
+ * outbound TCP, UDP, DNS or ping); commands, files and exposed ports still work. Set at
1828
+ * create only. Default `true`. Not available with a container volume or snapshot.
1829
+ */
1830
+ internetAccess?: boolean;
1823
1831
  timeoutMs?: number;
1824
1832
  /**
1825
1833
  * Region to run the sandbox in, e.g. `'us-east-1'`.
@@ -1829,7 +1837,7 @@ interface SandboxOpts extends ConnectionOpts {
1829
1837
  * is not in is rejected with a 400 rather than silently moved — that combination
1830
1838
  * cannot be satisfied.
1831
1839
  *
1832
- * Defaults to the platform's default sandbox region.
1840
+ * Defaults to `'us-east-1'`, or to the volume's or snapshot's region when one is given.
1833
1841
  */
1834
1842
  region?: string;
1835
1843
  /** Attach a persistent volume by id, mounted at `/workspace`. */
package/dist/index.js CHANGED
@@ -73,6 +73,7 @@ module.exports = __toCommonJS(index_exports);
73
73
  // src/config.ts
74
74
  var DEFAULT_API_URL = "https://lizard.build";
75
75
  var DEFAULT_SANDBOX_TIMEOUT_MS = 5 * 60 * 1e3;
76
+ var DEFAULT_SANDBOX_REGION = "us-east-1";
76
77
  var ConnectionConfig = class {
77
78
  constructor(opts) {
78
79
  this.apiKey = opts?.apiKey ?? process.env.LIZARD_API_KEY ?? "";
@@ -1686,12 +1687,21 @@ function coord(n) {
1686
1687
  }
1687
1688
 
1688
1689
  // src/sandbox/client.ts
1690
+ async function regionUnavailable(res) {
1691
+ try {
1692
+ const body = await res.clone().json();
1693
+ return body?.code === "region_unavailable";
1694
+ } catch {
1695
+ return false;
1696
+ }
1697
+ }
1689
1698
  var SandboxClient = class {
1690
1699
  static async createSandbox(template, timeoutMs, opts) {
1691
1700
  const ref = requireProjectRef(opts);
1692
1701
  const config = new ConnectionConfig(opts);
1693
1702
  const projectId = ref.projectId ?? await resolveProjectId(ref.project, config);
1694
- const res = await fetch(`${config.apiUrl}/api/sandboxes`, {
1703
+ const defaultRegion = !opts?.region && !opts?.volumeId && !opts?.volumeName && !opts?.snapshotId;
1704
+ const post = (region) => fetch(`${config.apiUrl}/api/sandboxes`, {
1695
1705
  method: "POST",
1696
1706
  headers: config.headers,
1697
1707
  body: JSON.stringify({
@@ -1702,14 +1712,24 @@ var SandboxClient = class {
1702
1712
  projectId,
1703
1713
  metadata: opts?.metadata,
1704
1714
  envs: opts?.envs,
1705
- region: opts?.region,
1715
+ region,
1706
1716
  volumeId: opts?.volumeId,
1707
1717
  volumeName: opts?.volumeName,
1708
- lizardToken: opts?.lizardToken
1718
+ lizardToken: opts?.lizardToken,
1719
+ // Sent only when asked: every other create stays what it was.
1720
+ ...opts?.internetAccess === false ? { internetAccess: false } : {}
1709
1721
  })
1710
1722
  });
1723
+ let res = await post(opts?.region || (defaultRegion ? DEFAULT_SANDBOX_REGION : void 0));
1724
+ if (defaultRegion && res.status === 503 && await regionUnavailable(res)) res = await post(void 0);
1711
1725
  if (!res.ok) await handleApiError(res);
1712
- return res.json();
1726
+ const created = await res.json();
1727
+ if (opts?.internetAccess === false && created.internetAccess !== false) {
1728
+ await this.killSandbox(created.sandboxId, opts).catch(() => {
1729
+ });
1730
+ throw new LizardError("This server does not support internetAccess: false yet; the sandbox it started had internet and was deleted");
1731
+ }
1732
+ return created;
1713
1733
  }
1714
1734
  static async killSandbox(sandboxId, opts) {
1715
1735
  const config = new ConnectionConfig(opts);
package/dist/index.mjs CHANGED
@@ -1,6 +1,7 @@
1
1
  // src/config.ts
2
2
  var DEFAULT_API_URL = "https://lizard.build";
3
3
  var DEFAULT_SANDBOX_TIMEOUT_MS = 5 * 60 * 1e3;
4
+ var DEFAULT_SANDBOX_REGION = "us-east-1";
4
5
  var ConnectionConfig = class {
5
6
  constructor(opts) {
6
7
  this.apiKey = opts?.apiKey ?? process.env.LIZARD_API_KEY ?? "";
@@ -1614,12 +1615,21 @@ function coord(n) {
1614
1615
  }
1615
1616
 
1616
1617
  // src/sandbox/client.ts
1618
+ async function regionUnavailable(res) {
1619
+ try {
1620
+ const body = await res.clone().json();
1621
+ return body?.code === "region_unavailable";
1622
+ } catch {
1623
+ return false;
1624
+ }
1625
+ }
1617
1626
  var SandboxClient = class {
1618
1627
  static async createSandbox(template, timeoutMs, opts) {
1619
1628
  const ref = requireProjectRef(opts);
1620
1629
  const config = new ConnectionConfig(opts);
1621
1630
  const projectId = ref.projectId ?? await resolveProjectId(ref.project, config);
1622
- const res = await fetch(`${config.apiUrl}/api/sandboxes`, {
1631
+ const defaultRegion = !opts?.region && !opts?.volumeId && !opts?.volumeName && !opts?.snapshotId;
1632
+ const post = (region) => fetch(`${config.apiUrl}/api/sandboxes`, {
1623
1633
  method: "POST",
1624
1634
  headers: config.headers,
1625
1635
  body: JSON.stringify({
@@ -1630,14 +1640,24 @@ var SandboxClient = class {
1630
1640
  projectId,
1631
1641
  metadata: opts?.metadata,
1632
1642
  envs: opts?.envs,
1633
- region: opts?.region,
1643
+ region,
1634
1644
  volumeId: opts?.volumeId,
1635
1645
  volumeName: opts?.volumeName,
1636
- lizardToken: opts?.lizardToken
1646
+ lizardToken: opts?.lizardToken,
1647
+ // Sent only when asked: every other create stays what it was.
1648
+ ...opts?.internetAccess === false ? { internetAccess: false } : {}
1637
1649
  })
1638
1650
  });
1651
+ let res = await post(opts?.region || (defaultRegion ? DEFAULT_SANDBOX_REGION : void 0));
1652
+ if (defaultRegion && res.status === 503 && await regionUnavailable(res)) res = await post(void 0);
1639
1653
  if (!res.ok) await handleApiError(res);
1640
- return res.json();
1654
+ const created = await res.json();
1655
+ if (opts?.internetAccess === false && created.internetAccess !== false) {
1656
+ await this.killSandbox(created.sandboxId, opts).catch(() => {
1657
+ });
1658
+ throw new LizardError("This server does not support internetAccess: false yet; the sandbox it started had internet and was deleted");
1659
+ }
1660
+ return created;
1641
1661
  }
1642
1662
  static async killSandbox(sandboxId, opts) {
1643
1663
  const config = new ConnectionConfig(opts);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lizard-build/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "TypeScript and JavaScript SDK for Lizard (lizard.build): cloud sandboxes for AI agents and code execution.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",