@gitterm/opencode-sandbox 0.0.0-stage → 0.1.1
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 +171 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +93746 -0
- package/dist/sandbox.d.ts +12 -0
- package/dist/sidebar.d.ts +10 -0
- package/dist/tui.d.ts +3 -0
- package/dist/tui.js +218 -0
- package/package.json +59 -4
package/README.md
CHANGED
|
@@ -1,3 +1,172 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @gitterm/opencode-sandbox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Let your [OpenCode](https://opencode.ai) agent run builds, tests, and preview servers in a
|
|
4
|
+
remote sandbox. Your conversation and files stay on your machine.
|
|
5
|
+
|
|
6
|
+
Want to move the whole session to the cloud instead? Use
|
|
7
|
+
[`@gitterm/opencode-cloud`](../opencode-cloud/README.md).
|
|
8
|
+
|
|
9
|
+
## 1. Install
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
opencode plugin add @gitterm/opencode-sandbox
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 2. Add your provider key
|
|
16
|
+
|
|
17
|
+
In `~/.config/opencode/opencode.json` (global), or a project's `opencode.json`. OpenCode's
|
|
18
|
+
background service doesn't load plugins from a project's config, so with a project config start
|
|
19
|
+
OpenCode with `opencode --standalone`.
|
|
20
|
+
|
|
21
|
+
```jsonc
|
|
22
|
+
{
|
|
23
|
+
"plugins": [
|
|
24
|
+
{
|
|
25
|
+
"package": "@gitterm/opencode-sandbox",
|
|
26
|
+
"options": {
|
|
27
|
+
"account": "e2b",
|
|
28
|
+
"accounts": {
|
|
29
|
+
"e2b": { "mode": "direct", "provider": "e2b", "apiKey": "{env:E2B_API_KEY}" },
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
}
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Never paste a key directly. OpenCode fills it in for you:
|
|
38
|
+
|
|
39
|
+
- `"{env:E2B_API_KEY}"` reads an environment variable.
|
|
40
|
+
- `"{file:~/.secrets/e2b}"` reads a file.
|
|
41
|
+
|
|
42
|
+
Restart OpenCode after changing the settings.
|
|
43
|
+
|
|
44
|
+
### Other providers
|
|
45
|
+
|
|
46
|
+
Add the account and set `"account"` to its name:
|
|
47
|
+
|
|
48
|
+
```jsonc
|
|
49
|
+
"daytona": { "mode": "direct", "provider": "daytona", "apiKey": "{env:DAYTONA_API_KEY}" },
|
|
50
|
+
"boat": { "mode": "direct", "provider": "boat", "apiKey": "{env:BOAT_API_KEY}" },
|
|
51
|
+
"vercel": { "mode": "direct", "provider": "vercel", "apiKey": "{env:VERCEL_TOKEN}", "teamId": "team_…", "projectId": "prj_…" },
|
|
52
|
+
"railway": { "mode": "direct", "provider": "railway", "apiKey": "{env:RAILWAY_TOKEN}", "projectId": "…", "environmentId": "…", "allowUnboundedLifetime": true },
|
|
53
|
+
"exedev": { "mode": "direct", "provider": "exedev", "apiKey": "{env:EXEDEV_API_KEY}", "allowUnboundedLifetime": true },
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Railway and exe.dev never delete a forgotten sandbox themselves, so they need
|
|
57
|
+
`allowUnboundedLifetime: true`. Destroy sandboxes you no longer need.
|
|
58
|
+
|
|
59
|
+
### Or use your GitTerm plan
|
|
60
|
+
|
|
61
|
+
No provider account needed. Sign in once, then use a managed account:
|
|
62
|
+
|
|
63
|
+
```sh
|
|
64
|
+
npm install -g @gitterm/cli
|
|
65
|
+
gitterm login
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```jsonc
|
|
69
|
+
"gitterm": { "mode": "managed", "size": "medium" },
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 3. Use it
|
|
73
|
+
|
|
74
|
+
Ask the agent, for example: _"Run the test suite in a sandbox."_ It will create a
|
|
75
|
+
sandbox, upload your checkout (uncommitted changes included, secret-like files skipped),
|
|
76
|
+
and run the command there. OpenCode asks before anything is created, uploaded, run, or
|
|
77
|
+
written back to your files.
|
|
78
|
+
|
|
79
|
+
Long builds and tests run in the background: you can keep talking to the agent, and it
|
|
80
|
+
gets a message when each job finishes.
|
|
81
|
+
|
|
82
|
+
| Tool | What it does |
|
|
83
|
+
| ------------------ | -------------------------------------------------------------------- |
|
|
84
|
+
| `sandbox_create` | Create a sandbox |
|
|
85
|
+
| `sandbox_list` | Show your account, who is charged, and your sandboxes |
|
|
86
|
+
| `sandbox_sync` | Upload your checkout |
|
|
87
|
+
| `sandbox_exec` | Run a command; with `background`, get a message when it finishes |
|
|
88
|
+
| `sandbox_job` | Check a command's output, or cancel it |
|
|
89
|
+
| `sandbox_preview` | Open a port, for example a dev server |
|
|
90
|
+
| `sandbox_artifact` | Download a file the command produced |
|
|
91
|
+
| `sandbox_apply` | Copy that file into your checkout, if your copy did not change since |
|
|
92
|
+
| `sandbox_snapshot` | Save or delete the project's setup snapshot (with `snapshots: true`) |
|
|
93
|
+
| `sandbox_destroy` | Delete a sandbox |
|
|
94
|
+
|
|
95
|
+
The right sidebar lists this checkout's sandboxes, with what each is running.
|
|
96
|
+
|
|
97
|
+
## Optional settings
|
|
98
|
+
|
|
99
|
+
```jsonc
|
|
100
|
+
"options": {
|
|
101
|
+
"account": "e2b",
|
|
102
|
+
"accounts": { … },
|
|
103
|
+
"limits": {
|
|
104
|
+
"maxSandboxes": 2,
|
|
105
|
+
"maxLifetimeMinutes": 60,
|
|
106
|
+
"defaultLifetimeMinutes": 30,
|
|
107
|
+
"maxJobMinutes": 30
|
|
108
|
+
},
|
|
109
|
+
"exclude": ["fixtures/large/**"],
|
|
110
|
+
"publicPreviews": true
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Machine size
|
|
115
|
+
|
|
116
|
+
You choose the size per account; the agent can't change it. If a build runs out of memory,
|
|
117
|
+
pick a bigger size:
|
|
118
|
+
|
|
119
|
+
```jsonc
|
|
120
|
+
"gitterm": { "mode": "managed", "size": "medium" },
|
|
121
|
+
"e2b": { "mode": "direct", "provider": "e2b", "apiKey": "{env:E2B_API_KEY}", "template": "my-8gb-template" },
|
|
122
|
+
"daytona": { "mode": "direct", "provider": "daytona", "apiKey": "{env:DAYTONA_API_KEY}", "resources": { "cpu": 4, "memory": 8 } },
|
|
123
|
+
"vercel": { "mode": "direct", "provider": "vercel", "apiKey": "{env:VERCEL_TOKEN}", "teamId": "team_…", "projectId": "prj_…", "vcpus": 4 },
|
|
124
|
+
"boat": { "mode": "direct", "provider": "boat", "apiKey": "{env:BOAT_API_KEY}", "size": "large" },
|
|
125
|
+
"exedev": { "mode": "direct", "provider": "exedev", "apiKey": "{env:EXEDEV_API_KEY}", "cpu": 4, "memory": "8GB", "allowUnboundedLifetime": true },
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
E2B's default `base` template has 512 MB of memory, too little for most builds. E2B sets
|
|
129
|
+
memory when a template is built, so build your own once
|
|
130
|
+
(`e2b template build --cpu-count 4 --memory-mb 8192`) and put its name in `template`.
|
|
131
|
+
|
|
132
|
+
`publicPreviews: true` makes every preview URL open to anyone who has it, with no
|
|
133
|
+
prompt. With your own key it works on E2B and Daytona. Boat, exe.dev, and Railway are
|
|
134
|
+
always private, so it is ignored there. Vercel is always public, so a Vercel sandbox can
|
|
135
|
+
only show previews when created with public previews (this setting, or your approval when
|
|
136
|
+
the agent asks). With a GitTerm plan, GitTerm serves the preview, so it also works on Boat
|
|
137
|
+
and exe.dev, and private previews open in your browser when you are signed in to GitTerm.
|
|
138
|
+
|
|
139
|
+
To stop being asked every time, allow actions in your OpenCode `permissions`:
|
|
140
|
+
|
|
141
|
+
```jsonc
|
|
142
|
+
"permissions": [
|
|
143
|
+
{ "action": "gitterm.sandbox.exec", "resource": "direct:e2b:*", "effect": "allow" }
|
|
144
|
+
]
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Setup snapshots
|
|
148
|
+
|
|
149
|
+
For a project with a slow setup, let the agent save a sandbox once dependencies are
|
|
150
|
+
installed, so the project's next sandboxes start ready:
|
|
151
|
+
|
|
152
|
+
```jsonc
|
|
153
|
+
"options": { "account": "e2b", "accounts": { … }, "snapshots": true }
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
Works with E2B, Daytona, Vercel, or Boat, with your own key or a GitTerm plan (Pro keeps 20 snapshots, Growth 100). The agent gets a `sandbox_snapshot`
|
|
157
|
+
tool and OpenCode asks before each save or delete. A project can have several snapshots
|
|
158
|
+
(say `deps` and `deps + postgres`), or the agent can save a general one for any project.
|
|
159
|
+
New sandboxes start from the project's newest one unless the agent picks another, and the
|
|
160
|
+
agent is told when a lockfile changed since a snapshot so it can replace it (the old one is
|
|
161
|
+
deleted). Snapshots are kept in your provider account until deleted. To let it save without asking, allow
|
|
162
|
+
`gitterm.sandbox.snapshot` in `permissions` as above.
|
|
163
|
+
|
|
164
|
+
To start every sandbox from a snapshot you made yourself, set it on the account instead;
|
|
165
|
+
the agent then doesn't manage snapshots for that account:
|
|
166
|
+
|
|
167
|
+
```jsonc
|
|
168
|
+
"e2b": { "mode": "direct", "provider": "e2b", "apiKey": "{env:E2B_API_KEY}", "snapshot": "my-snapshot:latest" },
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
More detail on costs, cleanup, and permissions:
|
|
172
|
+
[Agent sandboxes](../../docs/agent-sandboxes.md).
|
package/dist/index.d.ts
ADDED