@lizard-build/sdk 0.1.49 → 0.1.52
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 +25 -6
- package/dist/index.d.mts +392 -123
- package/dist/index.d.ts +392 -123
- package/dist/index.js +660 -267
- package/dist/index.mjs +659 -267
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Lizard SDK for TypeScript
|
|
2
2
|
|
|
3
|
-
Run commands, work with files and execute code in Linux sandboxes
|
|
3
|
+
Run commands, work with files and execute code in Linux sandboxes (Firecracker microVMs). The SDK also manages Lizard apps, databases, storage and projects.
|
|
4
4
|
|
|
5
5
|
## Install
|
|
6
6
|
|
|
@@ -79,7 +79,7 @@ Treat `url` like a credential: anyone with it can see and control the desktop. S
|
|
|
79
79
|
|
|
80
80
|
## Run Python
|
|
81
81
|
|
|
82
|
-
Run Python with the `interpreter` template. Each process command starts a separate Python process, so Python variables do not survive between calls
|
|
82
|
+
Run Python with the `interpreter` template. Each process command starts a separate Python process, so Python variables do not survive between calls; use `CodeSandbox` (below) when they should.
|
|
83
83
|
|
|
84
84
|
```ts
|
|
85
85
|
import { Sandbox } from '@lizard-build/sdk';
|
|
@@ -95,7 +95,26 @@ try {
|
|
|
95
95
|
}
|
|
96
96
|
```
|
|
97
97
|
|
|
98
|
-
|
|
98
|
+
To run code snippets with state carried between calls, use `CodeSandbox` (`runCode` / `run_code`): it boots the `interpreter` template and runs Python in a persistent Jupyter kernel inside the sandbox. See [Run code](https://github.com/lizard-build/lizard-sdk/blob/main/docs/sandboxes.md#run-code-codesandbox).
|
|
99
|
+
|
|
100
|
+
## Run code with state (CodeSandbox)
|
|
101
|
+
|
|
102
|
+
`CodeSandbox` boots the `interpreter` template and runs Python in a persistent Jupyter kernel inside the sandbox: variables survive between calls, the value of the last expression and matplotlib charts come back in `results`, and exceptions in `error`.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
import { CodeSandbox } from '@lizard-build/sdk';
|
|
106
|
+
|
|
107
|
+
const sandbox = await CodeSandbox.create({ projectId: 'proj_123' });
|
|
108
|
+
try {
|
|
109
|
+
await sandbox.runCode('x = 21');
|
|
110
|
+
const run = await sandbox.runCode('x * 2');
|
|
111
|
+
console.log(run.results[0].data); // "42"
|
|
112
|
+
} finally {
|
|
113
|
+
await sandbox.kill();
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
`language: 'bash'` (and `'javascript'` where `node` is installed; the `interpreter` template does not ship it) runs each call as a fresh process with no shared state.
|
|
99
118
|
|
|
100
119
|
## Configuration
|
|
101
120
|
|
|
@@ -105,13 +124,13 @@ Pass `timeoutMs` to `create()` to set the sandbox lifetime. The default is five
|
|
|
105
124
|
|
|
106
125
|
## Runtime limits
|
|
107
126
|
|
|
108
|
-
|
|
127
|
+
Each sandbox is a Firecracker microVM with its own kernel. Use volumes mounted at `/workspace` to keep files after a sandbox ends. `pause()`/`resume()` keep memory and running processes; `snapshot()` is ready in about 2 s and `Sandbox.restore()` starts a copy in about 0.4 s; `fork()` clones a running sandbox. File watching and sandbox log streaming are not available on Firecracker sandboxes yet, volumes cannot be resized yet, and a sandbox with a volume attached cannot be forked. See the [snapshot guide](../../docs/sandboxes.md#pause-resume-snapshots-and-fork).
|
|
109
128
|
|
|
110
|
-
`getHost()` returns a hostname without `https
|
|
129
|
+
`getHost()` returns a hostname without `https://`; the port is private, so send `sandbox.accessToken` as the `X-Lizard-Access-Token` header (or use `exposePort()`, which also returns a browser `url` carrying the token). File writes accept text or bytes (binary is sent exactly); `readBytes()` supports binary downloads.
|
|
111
130
|
|
|
112
131
|
## Current command and lifetime limits
|
|
113
132
|
|
|
114
|
-
Command results contain stdout, stderr, and the exit code. Command timeouts are limited to 1–600 seconds. The
|
|
133
|
+
Command results contain stdout, stderr, and the exit code. Command timeouts are limited to 1–600 seconds. The command options `envs`, `workdir` and `user` apply to that command; create-time `envs` apply to every command, and create-time `metadata` is returned by `getInfo()` / `get_info()`.
|
|
115
134
|
|
|
116
135
|
The SDK and CLI default to a five-minute lifetime. The raw API and dashboard default to no expiration. Set an explicit lifetime: `timeoutMs: 0` at creation disables expiration; a positive value sets a deadline. `setTimeout` accepts 1000–2147483647 ms, not zero. Commands do not reset the deadline. This is not an idle timer.
|
|
117
136
|
|