opencode-sandbox 0.1.22 → 0.1.23
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 +31 -5
- package/dist/config.d.ts +1 -0
- package/dist/index.js +21 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -125,10 +125,25 @@ Everything else is **blocked by default**.
|
|
|
125
125
|
|
|
126
126
|
## Configuration
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
Config files are stored outside the project directory (in `~/.config/opencode-sandbox/`) so that sandboxed commands cannot modify them. This prevents indirect prompt injection from weakening the sandbox by overwriting the config.
|
|
129
|
+
|
|
130
|
+
### Config file locations
|
|
131
|
+
|
|
132
|
+
The plugin searches for configuration in this order (first match wins):
|
|
133
|
+
|
|
134
|
+
1. **Environment variable** `OPENCODE_SANDBOX_CONFIG` (JSON string)
|
|
135
|
+
2. **Per-project config** `~/.config/opencode-sandbox/projects/<project-name>.json`
|
|
136
|
+
3. **Global config** `~/.config/opencode-sandbox/config.json`
|
|
137
|
+
4. **Built-in defaults**
|
|
138
|
+
|
|
139
|
+
The `<project-name>` is the basename of the project directory (e.g., `my-app` for `/home/user/projects/my-app`).
|
|
140
|
+
|
|
141
|
+
If `XDG_CONFIG_HOME` is set, it is used instead of `~/.config`.
|
|
142
|
+
|
|
143
|
+
### Example: Global config
|
|
129
144
|
|
|
130
145
|
```json
|
|
131
|
-
//
|
|
146
|
+
// ~/.config/opencode-sandbox/config.json
|
|
132
147
|
{
|
|
133
148
|
"filesystem": {
|
|
134
149
|
"denyRead": ["~/.ssh", "~/.aws/credentials"],
|
|
@@ -149,19 +164,30 @@ Everything else is **blocked by default**.
|
|
|
149
164
|
}
|
|
150
165
|
```
|
|
151
166
|
|
|
152
|
-
###
|
|
167
|
+
### Example: Per-project config
|
|
168
|
+
|
|
169
|
+
```json
|
|
170
|
+
// ~/.config/opencode-sandbox/projects/my-app.json
|
|
171
|
+
{
|
|
172
|
+
"network": {
|
|
173
|
+
"allowedDomains": ["my-internal-api.company.com"]
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Environment variable
|
|
153
179
|
|
|
154
180
|
```bash
|
|
155
181
|
OPENCODE_SANDBOX_CONFIG='{"filesystem":{"denyRead":["~/.ssh"]},"network":{"allowedDomains":["github.com"]}}' opencode
|
|
156
182
|
```
|
|
157
183
|
|
|
158
|
-
###
|
|
184
|
+
### Disable
|
|
159
185
|
|
|
160
186
|
```bash
|
|
161
187
|
OPENCODE_DISABLE_SANDBOX=1 opencode
|
|
162
188
|
```
|
|
163
189
|
|
|
164
|
-
Or in
|
|
190
|
+
Or in any config file:
|
|
165
191
|
|
|
166
192
|
```json
|
|
167
193
|
{
|
package/dist/config.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export interface SandboxPluginConfig {
|
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
17
|
export declare function resolveConfig(projectDir: string, worktree: string, user?: SandboxPluginConfig): SandboxRuntimeConfig;
|
|
18
|
+
export declare function getConfigDir(): string;
|
|
18
19
|
export declare function loadConfig(projectDir: string): Promise<SandboxPluginConfig>;
|
package/dist/index.js
CHANGED
|
@@ -68,6 +68,18 @@ function resolveConfig(projectDir, worktree, user) {
|
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
|
+
function getConfigDir() {
|
|
72
|
+
const xdgConfig = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
|
|
73
|
+
return path.join(xdgConfig, "opencode-sandbox");
|
|
74
|
+
}
|
|
75
|
+
async function tryLoadJsonFile(filePath) {
|
|
76
|
+
try {
|
|
77
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
78
|
+
return JSON.parse(content);
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
71
83
|
async function loadConfig(projectDir) {
|
|
72
84
|
const envConfig = process.env.OPENCODE_SANDBOX_CONFIG;
|
|
73
85
|
if (envConfig) {
|
|
@@ -77,13 +89,15 @@ async function loadConfig(projectDir) {
|
|
|
77
89
|
console.warn("[opencode-sandbox] Invalid JSON in OPENCODE_SANDBOX_CONFIG, using defaults");
|
|
78
90
|
}
|
|
79
91
|
}
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
92
|
+
const configDir = getConfigDir();
|
|
93
|
+
const projectName = path.basename(projectDir);
|
|
94
|
+
const projectConfig = await tryLoadJsonFile(path.join(configDir, "projects", `${projectName}.json`));
|
|
95
|
+
if (projectConfig)
|
|
96
|
+
return projectConfig;
|
|
97
|
+
const globalConfig = await tryLoadJsonFile(path.join(configDir, "config.json"));
|
|
98
|
+
if (globalConfig)
|
|
99
|
+
return globalConfig;
|
|
100
|
+
return {};
|
|
87
101
|
}
|
|
88
102
|
|
|
89
103
|
// src/index.ts
|
package/package.json
CHANGED