@cloudflare/sandbox 0.0.0-037c848
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/CHANGELOG.md +45 -0
- package/Dockerfile +16 -0
- package/README.md +65 -0
- package/container_src/index.ts +2906 -0
- package/container_src/package.json +9 -0
- package/package.json +40 -0
- package/src/client.ts +1960 -0
- package/src/index.ts +136 -0
- package/tests/client.example.ts +308 -0
- package/tests/connection-test.ts +81 -0
- package/tests/simple-test.ts +81 -0
- package/tests/test1.ts +281 -0
- package/tests/test2.ts +929 -0
- package/tsconfig.json +3 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# @cloudflare/sandbox
|
|
2
|
+
|
|
3
|
+
## 0.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`d1c7c99`](https://github.com/cloudflare/sandbox-sdk/commit/d1c7c99df6555eff71bcd59852e4b8eed2ad8cb6) Thanks [@threepointone](https://github.com/threepointone)! - fix file operations
|
|
8
|
+
|
|
9
|
+
## 0.0.6
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#9](https://github.com/cloudflare/sandbox-sdk/pull/9) [`24f5470`](https://github.com/cloudflare/sandbox-sdk/commit/24f547048d5a26137de4656cea13d83ad2cc0b43) Thanks [@ItsWendell](https://github.com/ItsWendell)! - fix baseUrl for stub and stub forwarding
|
|
14
|
+
|
|
15
|
+
## 0.0.5
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [#5](https://github.com/cloudflare/sandbox-sdk/pull/5) [`7c15b81`](https://github.com/cloudflare/sandbox-sdk/commit/7c15b817899e4d9e1f25747aaf439e5e9e880d15) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Make package ready for deployment
|
|
20
|
+
|
|
21
|
+
## 0.0.4
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- [`c0d9d33`](https://github.com/cloudflare/sandbox-sdk/commit/c0d9d3396badee1eab45e6b4a73d48957f31409b) Thanks [@threepointone](https://github.com/threepointone)! - actually work
|
|
26
|
+
|
|
27
|
+
- [`444d2da`](https://github.com/cloudflare/sandbox-sdk/commit/444d2dafde9a0f190e50c879b0e768da1b289b51) Thanks [@threepointone](https://github.com/threepointone)! - add experimental label
|
|
28
|
+
|
|
29
|
+
## 0.0.3
|
|
30
|
+
|
|
31
|
+
### Patch Changes
|
|
32
|
+
|
|
33
|
+
- [`2b087c4`](https://github.com/cloudflare/sandbox-sdk/commit/2b087c40a29697c20dad19b4e3b8512f5d404bd3) Thanks [@ghostwriternr](https://github.com/ghostwriternr)! - Fix worker unable to find container port
|
|
34
|
+
|
|
35
|
+
## 0.0.2
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- [`52f02f0`](https://github.com/cloudflare/sandbox-sdk/commit/52f02f0625ef9f8eac695e51f93fa79651c0206d) Thanks [@threepointone](https://github.com/threepointone)! - readFile
|
|
40
|
+
|
|
41
|
+
## 0.0.1
|
|
42
|
+
|
|
43
|
+
### Patch Changes
|
|
44
|
+
|
|
45
|
+
- [`f786c3c`](https://github.com/cloudflare/sandbox-sdk/commit/f786c3cee6bd9777bd74918ae9fdf381aa99f913) Thanks [@threepointone](https://github.com/threepointone)! - Release!
|
package/Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# syntax=docker/dockerfile:1
|
|
2
|
+
|
|
3
|
+
FROM oven/bun:latest
|
|
4
|
+
# Set destination for COPY
|
|
5
|
+
WORKDIR /app
|
|
6
|
+
|
|
7
|
+
# Install git
|
|
8
|
+
RUN apt-get update && apt-get install -y git
|
|
9
|
+
|
|
10
|
+
COPY container_src/* ./
|
|
11
|
+
# RUN bun install
|
|
12
|
+
|
|
13
|
+
EXPOSE 3000
|
|
14
|
+
# Run
|
|
15
|
+
CMD ["bun", "index.ts"]
|
|
16
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
## @cloudflare/sandbox
|
|
2
|
+
|
|
3
|
+
> **⚠️ Experimental** - This library is currently experimental and we're actively seeking feedback. Please try it out and let us know what you think!
|
|
4
|
+
|
|
5
|
+
A library to spin up a sandboxed environment.
|
|
6
|
+
|
|
7
|
+
First, setup your wrangler.json to use the sandbox:
|
|
8
|
+
|
|
9
|
+
```jsonc
|
|
10
|
+
{
|
|
11
|
+
// ...
|
|
12
|
+
"containers": [
|
|
13
|
+
{
|
|
14
|
+
"class_name": "Sandbox",
|
|
15
|
+
"image": "./node_modules/@cloudflare/sandbox/Dockerfile",
|
|
16
|
+
"name": "sandbox"
|
|
17
|
+
}
|
|
18
|
+
],
|
|
19
|
+
"durable_objects": {
|
|
20
|
+
"bindings": [
|
|
21
|
+
{
|
|
22
|
+
"class_name": "Sandbox",
|
|
23
|
+
"name": "Sandbox"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
"migrations": [
|
|
28
|
+
{
|
|
29
|
+
"new_sqlite_classes": ["Sandbox"],
|
|
30
|
+
"tag": "v1"
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Then, export the Sandbox class in your worker:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
export { Sandbox } from "@cloudflare/sandbox";
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
You can then use the Sandbox class in your worker:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { getSandbox } from "@cloudflare/sandbox";
|
|
46
|
+
|
|
47
|
+
export default {
|
|
48
|
+
async fetch(request: Request, env: Env) {
|
|
49
|
+
const sandbox = getSandbox(env.Sandbox, "my-sandbox");
|
|
50
|
+
return sandbox.exec("ls", ["-la"]);
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Methods:
|
|
56
|
+
|
|
57
|
+
- `exec(command: string, args: string[], options?: { stream?: boolean })`: Execute a command in the sandbox.
|
|
58
|
+
- `gitCheckout(repoUrl: string, options: { branch?: string; targetDir?: string; stream?: boolean })`: Checkout a git repository in the sandbox.
|
|
59
|
+
- `mkdir(path: string, options: { recursive?: boolean; stream?: boolean })`: Create a directory in the sandbox.
|
|
60
|
+
- `writeFile(path: string, content: string, options: { encoding?: string; stream?: boolean })`: Write content to a file in the sandbox.
|
|
61
|
+
- `readFile(path: string, options: { encoding?: string; stream?: boolean })`: Read content from a file in the sandbox.
|
|
62
|
+
- `deleteFile(path: string, options?: { stream?: boolean })`: Delete a file from the sandbox.
|
|
63
|
+
- `renameFile(oldPath: string, newPath: string, options?: { stream?: boolean })`: Rename a file in the sandbox.
|
|
64
|
+
- `moveFile(sourcePath: string, destinationPath: string, options?: { stream?: boolean })`: Move a file from one location to another in the sandbox.
|
|
65
|
+
- `ping()`: Ping the sandbox.
|