@lightningai/sdk 2026.7.2 → 2026.7.3
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 +128 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,50 +1,154 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @lightningai/sdk
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
**Create and control Lightning AI sandboxes from TypeScript.**
|
|
6
|
+
|
|
7
|
+
______________________________________________________________________
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="#quick-start">Quick start</a> •
|
|
11
|
+
<a href="#examples">Examples</a> •
|
|
12
|
+
<a href="#api-shape">API shape</a> •
|
|
13
|
+
<a href="#development">Development</a> •
|
|
14
|
+
<a href="https://lightning.ai/docs/platform/developers/sdk/sandbox">Docs</a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
[](https://www.npmjs.com/package/@lightningai/sdk)
|
|
18
|
+
[](package.json)
|
|
19
|
+
[](../LICENSE)
|
|
20
|
+
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
# Why @lightningai/sdk?
|
|
4
24
|
|
|
5
|
-
|
|
25
|
+
`@lightningai/sdk` is the TypeScript SDK for Lightning AI sandboxes. Use it when
|
|
26
|
+
Node.js code needs an isolated machine for commands, file operations, PTY
|
|
27
|
+
sessions, snapshots, or short-lived automation.
|
|
6
28
|
|
|
7
|
-
|
|
29
|
+
The package is intentionally narrow: it focuses on sandboxes and mirrors the
|
|
30
|
+
Python sandbox surface where possible.
|
|
8
31
|
|
|
9
|
-
|
|
32
|
+
Build on [Lightning AI](https://lightning.ai), the platform for training,
|
|
33
|
+
deploying, and scaling AI applications with managed compute, collaborative
|
|
34
|
+
studios, and production endpoints.
|
|
35
|
+
|
|
36
|
+
# Quick start
|
|
37
|
+
|
|
38
|
+
Install the package:
|
|
10
39
|
|
|
11
40
|
```bash
|
|
12
41
|
npm install @lightningai/sdk
|
|
13
42
|
```
|
|
14
43
|
|
|
15
|
-
|
|
16
|
-
> This package is published as an ES Module (ESM) only. For applications using CommonJS, use `await import("@lightningai/sdk")` to import and use this package.
|
|
44
|
+
Set an API key:
|
|
17
45
|
|
|
18
|
-
|
|
46
|
+
```bash
|
|
47
|
+
export LIGHTNING_API_KEY="..."
|
|
48
|
+
```
|
|
19
49
|
|
|
20
|
-
|
|
50
|
+
Create a sandbox and run a command:
|
|
21
51
|
|
|
22
|
-
```
|
|
23
|
-
|
|
52
|
+
```ts
|
|
53
|
+
import { Sandbox } from "@lightningai/sdk";
|
|
54
|
+
|
|
55
|
+
const sandbox = await Sandbox.create({
|
|
56
|
+
name: "typescript-readme",
|
|
57
|
+
instanceType: "cpu-1",
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const result = await sandbox.runCommand("echo", ["hello from Lightning"]);
|
|
61
|
+
console.log(result.output);
|
|
62
|
+
|
|
63
|
+
await sandbox.delete();
|
|
24
64
|
```
|
|
25
65
|
|
|
66
|
+
This package is ESM-only. In CommonJS projects, import it dynamically:
|
|
67
|
+
|
|
68
|
+
```js
|
|
69
|
+
const { Sandbox } = await import("@lightningai/sdk");
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
# Examples
|
|
73
|
+
|
|
74
|
+
## Files
|
|
75
|
+
|
|
26
76
|
```ts
|
|
27
77
|
import { Sandbox } from "@lightningai/sdk";
|
|
28
78
|
|
|
29
|
-
|
|
30
|
-
const sandbox = await Sandbox.create({
|
|
31
|
-
name: "quickstart",
|
|
32
|
-
instanceType: "cpu-1",
|
|
33
|
-
});
|
|
79
|
+
const sandbox = await Sandbox.create({ instanceType: "cpu-1" });
|
|
34
80
|
|
|
35
|
-
|
|
36
|
-
|
|
81
|
+
await sandbox.fs.writeFile({
|
|
82
|
+
path: "/workspace/app.js",
|
|
83
|
+
content: "console.log('hello from a file')\n",
|
|
84
|
+
});
|
|
37
85
|
|
|
38
|
-
|
|
39
|
-
|
|
86
|
+
const result = await sandbox.runCommand("node", ["/workspace/app.js"]);
|
|
87
|
+
console.log(result.output);
|
|
40
88
|
|
|
41
|
-
|
|
89
|
+
await sandbox.delete();
|
|
42
90
|
```
|
|
43
91
|
|
|
44
|
-
##
|
|
92
|
+
## Persistent sandbox
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { Sandbox } from "@lightningai/sdk";
|
|
96
|
+
|
|
97
|
+
const sandbox = await Sandbox.create({
|
|
98
|
+
name: "persistent-devbox",
|
|
99
|
+
instanceType: "cpu-1",
|
|
100
|
+
persistent: true,
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
await sandbox.runCommand("mkdir", ["-p", "/workspace/project"]);
|
|
104
|
+
await sandbox.stop();
|
|
105
|
+
|
|
106
|
+
const resumed = await Sandbox.resume({ sandboxId: sandbox.sandboxId });
|
|
107
|
+
console.log(resumed.status);
|
|
108
|
+
|
|
109
|
+
await resumed.delete();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## PTY session
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { Sandbox, writeToStdout } from "@lightningai/sdk";
|
|
116
|
+
|
|
117
|
+
const sandbox = await Sandbox.create({ instanceType: "cpu-1" });
|
|
118
|
+
|
|
119
|
+
const pty = await sandbox.process.createPty({
|
|
120
|
+
sessionName: "shell",
|
|
121
|
+
onData: writeToStdout,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
await pty.sendInput("python --version\n");
|
|
125
|
+
await pty.sendInput("exit\n");
|
|
126
|
+
await pty.wait();
|
|
127
|
+
|
|
128
|
+
await sandbox.delete();
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
# API shape
|
|
132
|
+
|
|
133
|
+
| Area | Entry point |
|
|
134
|
+
| ----------------------------- | ----------------------------------------------------------- |
|
|
135
|
+
| Create/get/list/resume/delete | `Sandbox` |
|
|
136
|
+
| Run commands | `sandbox.runCommand(...)` |
|
|
137
|
+
| Files and directories | `sandbox.fs` |
|
|
138
|
+
| PTY sessions | `sandbox.process` |
|
|
139
|
+
| Snapshots | `sandbox.createSnapshot(...)`, `Sandbox.listSnapshots(...)` |
|
|
140
|
+
| Network egress policy | `networkPolicy` on `Sandbox.create(...)` |
|
|
141
|
+
|
|
142
|
+
# Development
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
npm install
|
|
146
|
+
npm run build
|
|
147
|
+
npm test
|
|
148
|
+
```
|
|
45
149
|
|
|
46
|
-
|
|
150
|
+
The package is published as an ES module and requires Node.js 22 or newer.
|
|
47
151
|
|
|
48
|
-
|
|
152
|
+
# License
|
|
49
153
|
|
|
50
|
-
Apache-2.0
|
|
154
|
+
Apache-2.0. See [`../LICENSE`](../LICENSE).
|