elsabro 2.2.0 → 3.7.0
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 +668 -20
- package/agents/elsabro-orchestrator.md +113 -0
- package/bin/install.js +0 -0
- package/commands/elsabro/execute.md +223 -46
- package/commands/elsabro/start.md +34 -0
- package/commands/elsabro/verify-work.md +29 -0
- package/flows/development-flow.json +452 -0
- package/flows/quick-flow.json +118 -0
- package/hooks/confirm-destructive.sh +145 -0
- package/hooks/hooks-config.json +81 -0
- package/hooks/lint-check.sh +238 -0
- package/hooks/post-edit-test.sh +189 -0
- package/package.json +5 -3
- package/references/SYSTEM_INDEX.md +379 -5
- package/references/agent-marketplace.md +2274 -0
- package/references/agent-protocol.md +1126 -0
- package/references/ai-code-suggestions.md +2413 -0
- package/references/checkpointing.md +595 -0
- package/references/collaboration-patterns.md +851 -0
- package/references/collaborative-sessions.md +1081 -0
- package/references/configuration-management.md +1810 -0
- package/references/cost-tracking.md +1095 -0
- package/references/enterprise-sso.md +2001 -0
- package/references/error-contracts-tests.md +1171 -0
- package/references/error-contracts-v2.md +968 -0
- package/references/error-contracts.md +3102 -0
- package/references/event-driven.md +1031 -0
- package/references/flow-orchestration.md +940 -0
- package/references/flow-visualization.md +1557 -0
- package/references/ide-integrations.md +3513 -0
- package/references/interrupt-system.md +681 -0
- package/references/kubernetes-deployment.md +3099 -0
- package/references/memory-system.md +683 -0
- package/references/mobile-companion.md +3236 -0
- package/references/multi-llm-providers.md +2494 -0
- package/references/multi-project-memory.md +1182 -0
- package/references/observability.md +793 -0
- package/references/output-schemas.md +858 -0
- package/references/parallel-worktrees.md +293 -0
- package/references/performance-profiler.md +955 -0
- package/references/plugin-system.md +1526 -0
- package/references/prompt-management.md +292 -0
- package/references/sandbox-execution.md +303 -0
- package/references/security-system.md +1253 -0
- package/references/streaming.md +696 -0
- package/references/testing-framework.md +1151 -0
- package/references/time-travel.md +802 -0
- package/references/tool-registry.md +886 -0
- package/references/voice-commands.md +3296 -0
- package/scripts/setup-parallel-worktrees.sh +319 -0
- package/skills/memory-update.md +207 -0
- package/skills/review.md +331 -0
- package/skills/techdebt.md +289 -0
- package/skills/tutor.md +219 -0
- package/templates/.planning/notes/.gitkeep +0 -0
- package/templates/CLAUDE.md.template +48 -0
- package/templates/agent-marketplace-config.json +220 -0
- package/templates/agent-protocol-config.json +136 -0
- package/templates/ai-suggestions-config.json +100 -0
- package/templates/checkpoint-state.json +61 -0
- package/templates/collaboration-config.json +157 -0
- package/templates/collaborative-sessions-config.json +153 -0
- package/templates/configuration-config.json +245 -0
- package/templates/cost-tracking-config.json +148 -0
- package/templates/enterprise-sso-config.json +438 -0
- package/templates/error-handling-config.json +79 -2
- package/templates/events-config.json +148 -0
- package/templates/flow-visualization-config.json +196 -0
- package/templates/ide-integrations-config.json +442 -0
- package/templates/kubernetes-config.json +764 -0
- package/templates/memory-state.json +84 -0
- package/templates/mistakes.md.template +52 -0
- package/templates/mobile-companion-config.json +600 -0
- package/templates/multi-llm-config.json +544 -0
- package/templates/multi-project-memory-config.json +145 -0
- package/templates/observability-config.json +109 -0
- package/templates/patterns.md.template +114 -0
- package/templates/performance-profiler-config.json +125 -0
- package/templates/plugin-config.json +170 -0
- package/templates/prompt-management-config.json +86 -0
- package/templates/sandbox-config.json +185 -0
- package/templates/schemas-config.json +65 -0
- package/templates/security-config.json +120 -0
- package/templates/streaming-config.json +72 -0
- package/templates/testing-config.json +81 -0
- package/templates/timetravel-config.json +62 -0
- package/templates/tool-registry-config.json +109 -0
- package/templates/voice-commands-config.json +658 -0
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
# Prompt Management System (v3.3)
|
|
2
|
+
|
|
3
|
+
Sistema de gestión de prompts con templates, versionado, variables, y optimización A/B.
|
|
4
|
+
|
|
5
|
+
## Arquitectura
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
9
|
+
│ PROMPT MANAGEMENT SYSTEM │
|
|
10
|
+
├─────────────────────────────────────────────────────────────────────────┤
|
|
11
|
+
│ │
|
|
12
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
13
|
+
│ │ PROMPT REGISTRY │ │
|
|
14
|
+
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
|
|
15
|
+
│ │ │ Template Library │ │ │
|
|
16
|
+
│ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │
|
|
17
|
+
│ │ │ │ explore │ │ analyze │ │implement│ │ review │ │ │ │
|
|
18
|
+
│ │ │ │ v2.1 │ │ v1.3 │ │ v3.0 │ │ v2.0 │ │ │ │
|
|
19
|
+
│ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ │
|
|
20
|
+
│ │ └─────────────────────────────────────────────────────────┘ │ │
|
|
21
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
22
|
+
│ │ │
|
|
23
|
+
│ ▼ │
|
|
24
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
25
|
+
│ │ TEMPLATE ENGINE │ │
|
|
26
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
27
|
+
│ │ │ Variables │ │ Conditionals│ │ Loops │ │ │
|
|
28
|
+
│ │ │ {{var}} │ │ {{#if}} │ │ {{#each}} │ │ │
|
|
29
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
30
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
31
|
+
│ │ │
|
|
32
|
+
│ ▼ │
|
|
33
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
34
|
+
│ │ A/B TESTING & OPTIMIZATION │ │
|
|
35
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
36
|
+
│ │ │ Experiments │ │ Metrics │ │ Analysis │ │ │
|
|
37
|
+
│ │ │ A vs B │ │ tracking │ │ & Winner │ │ │
|
|
38
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
39
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
40
|
+
│ │
|
|
41
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## PromptRegistry API
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
interface PromptTemplate {
|
|
50
|
+
id: string;
|
|
51
|
+
name: string;
|
|
52
|
+
version: string;
|
|
53
|
+
description: string;
|
|
54
|
+
category: string;
|
|
55
|
+
template: string;
|
|
56
|
+
variables: TemplateVariable[];
|
|
57
|
+
settings: { model?: string; temperature?: number; maxTokens?: number };
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
class PromptRegistry {
|
|
61
|
+
// Register new template
|
|
62
|
+
register(template: PromptTemplate): PromptTemplate;
|
|
63
|
+
|
|
64
|
+
// Get template (latest version by default)
|
|
65
|
+
get(name: string, version?: string): PromptTemplate | undefined;
|
|
66
|
+
|
|
67
|
+
// List all templates
|
|
68
|
+
list(options?: { category?: string }): PromptTemplate[];
|
|
69
|
+
|
|
70
|
+
// List versions for template
|
|
71
|
+
listVersions(name: string): string[];
|
|
72
|
+
|
|
73
|
+
// Create alias
|
|
74
|
+
alias(alias: string, name: string): void;
|
|
75
|
+
|
|
76
|
+
// Export/Import templates
|
|
77
|
+
export(): PromptRegistryExport;
|
|
78
|
+
import(data: PromptRegistryExport): number;
|
|
79
|
+
}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## TemplateEngine
|
|
85
|
+
|
|
86
|
+
Renderizado de templates con variables, condicionales y loops.
|
|
87
|
+
|
|
88
|
+
### Sintaxis
|
|
89
|
+
|
|
90
|
+
| Sintaxis | Descripción | Ejemplo |
|
|
91
|
+
|----------|-------------|---------|
|
|
92
|
+
| `{{variable}}` | Variable simple | `{{name}}` |
|
|
93
|
+
| `{{object.property}}` | Acceso a propiedades | `{{user.email}}` |
|
|
94
|
+
| `{{#if condition}}...{{/if}}` | Condicional | `{{#if hasError}}Error{{/if}}` |
|
|
95
|
+
| `{{#each items}}...{{/each}}` | Loop | `{{#each files}}{{this}}{{/each}}` |
|
|
96
|
+
| `{{helper arg}}` | Helper | `{{uppercase name}}` |
|
|
97
|
+
|
|
98
|
+
### Helpers Disponibles
|
|
99
|
+
|
|
100
|
+
| Helper | Descripción | Ejemplo |
|
|
101
|
+
|--------|-------------|---------|
|
|
102
|
+
| `uppercase` | Mayúsculas | `{{uppercase text}}` |
|
|
103
|
+
| `lowercase` | Minúsculas | `{{lowercase text}}` |
|
|
104
|
+
| `capitalize` | Capitalizar | `{{capitalize word}}` |
|
|
105
|
+
| `trim` | Eliminar espacios | `{{trim input}}` |
|
|
106
|
+
| `length` | Longitud de array | `{{length items}}` |
|
|
107
|
+
| `join` | Unir array | `{{join items ", "}}` |
|
|
108
|
+
| `json` | Formatear JSON | `{{json object}}` |
|
|
109
|
+
| `date` | Formatear fecha | `{{date now "date"}}` |
|
|
110
|
+
| `default` | Valor por defecto | `{{default value "N/A"}}` |
|
|
111
|
+
| `truncate` | Truncar texto | `{{truncate text 100}}` |
|
|
112
|
+
|
|
113
|
+
### Ejemplo de Uso
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const engine = new TemplateEngine();
|
|
117
|
+
|
|
118
|
+
const template = `
|
|
119
|
+
You are {{role}}. Your task is to {{task}}.
|
|
120
|
+
|
|
121
|
+
{{#if context}}
|
|
122
|
+
Context: {{context}}
|
|
123
|
+
{{/if}}
|
|
124
|
+
|
|
125
|
+
{{#each requirements}}
|
|
126
|
+
- {{this}}
|
|
127
|
+
{{/each}}
|
|
128
|
+
`;
|
|
129
|
+
|
|
130
|
+
const result = engine.render(template, {
|
|
131
|
+
role: 'code reviewer',
|
|
132
|
+
task: 'review the changes',
|
|
133
|
+
context: 'PR #123',
|
|
134
|
+
requirements: ['Check security', 'Verify tests']
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
---
|
|
139
|
+
|
|
140
|
+
## PromptOptimizer (A/B Testing)
|
|
141
|
+
|
|
142
|
+
### Crear Experimento
|
|
143
|
+
|
|
144
|
+
```typescript
|
|
145
|
+
const optimizer = new PromptOptimizer(registry);
|
|
146
|
+
|
|
147
|
+
const experiment = optimizer.createExperiment({
|
|
148
|
+
name: 'Review prompt optimization',
|
|
149
|
+
promptName: 'review',
|
|
150
|
+
variants: [
|
|
151
|
+
{ id: 'control', name: 'Control', version: '1.0.0' },
|
|
152
|
+
{ id: 'variant_a', name: 'More structured', version: '1.1.0' }
|
|
153
|
+
],
|
|
154
|
+
traffic: [50, 50], // 50/50 split
|
|
155
|
+
metrics: ['success_rate', 'quality_score']
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
optimizer.startExperiment(experiment.id);
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Obtener Variante
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
// Get variant for request (based on traffic allocation)
|
|
165
|
+
const variant = optimizer.getVariant(experimentId);
|
|
166
|
+
const template = registry.get(promptName, variant.version);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Registrar Resultado
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
optimizer.recordResult(experimentId, variantId, {
|
|
173
|
+
success_rate: 1,
|
|
174
|
+
quality_score: 85
|
|
175
|
+
});
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Analizar Resultados
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
const analysis = optimizer.analyzeExperiment(experimentId);
|
|
182
|
+
// {
|
|
183
|
+
// winner: 'variant_a',
|
|
184
|
+
// confidence: 0.95,
|
|
185
|
+
// recommendation: 'Promote variant_a (12.5% improvement)'
|
|
186
|
+
// }
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Templates Predefinidos
|
|
192
|
+
|
|
193
|
+
### explore (v1.0.0)
|
|
194
|
+
```
|
|
195
|
+
You are an expert code explorer. Your task is to understand and map the codebase.
|
|
196
|
+
|
|
197
|
+
## Task
|
|
198
|
+
{{task}}
|
|
199
|
+
|
|
200
|
+
## Focus Areas
|
|
201
|
+
{{#each focusAreas}}
|
|
202
|
+
- {{this}}
|
|
203
|
+
{{/each}}
|
|
204
|
+
|
|
205
|
+
## Output Requirements
|
|
206
|
+
Provide a structured analysis including:
|
|
207
|
+
1. File structure overview
|
|
208
|
+
2. Key components identified
|
|
209
|
+
3. Dependencies and relationships
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### implement (v1.0.0)
|
|
213
|
+
```
|
|
214
|
+
You are an expert software engineer. Implement the following feature.
|
|
215
|
+
|
|
216
|
+
## Feature
|
|
217
|
+
{{feature}}
|
|
218
|
+
|
|
219
|
+
## Requirements
|
|
220
|
+
{{#each requirements}}
|
|
221
|
+
- {{this}}
|
|
222
|
+
{{/each}}
|
|
223
|
+
|
|
224
|
+
## Technical Context
|
|
225
|
+
- Language: {{language}}
|
|
226
|
+
- Framework: {{framework}}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### review (v1.0.0)
|
|
230
|
+
```
|
|
231
|
+
You are a senior code reviewer. Review the following code changes.
|
|
232
|
+
|
|
233
|
+
## Code to Review
|
|
234
|
+
{{code}}
|
|
235
|
+
|
|
236
|
+
## Review Criteria
|
|
237
|
+
1. Correctness
|
|
238
|
+
2. Security
|
|
239
|
+
3. Performance
|
|
240
|
+
4. Maintainability
|
|
241
|
+
5. Testing
|
|
242
|
+
|
|
243
|
+
Provide: Summary, Issues, Suggestions, Approval status
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Comandos
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
/elsabro:prompt list # Listar templates
|
|
252
|
+
/elsabro:prompt show explore # Ver template
|
|
253
|
+
/elsabro:prompt versions explore # Ver versiones
|
|
254
|
+
/elsabro:prompt create # Crear nuevo template
|
|
255
|
+
/elsabro:prompt test explore # Probar template
|
|
256
|
+
/elsabro:prompt experiment create # Crear A/B test
|
|
257
|
+
/elsabro:prompt experiment status # Ver experimentos
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
---
|
|
261
|
+
|
|
262
|
+
## Configuración
|
|
263
|
+
|
|
264
|
+
```json
|
|
265
|
+
{
|
|
266
|
+
"promptManagement": {
|
|
267
|
+
"enabled": true,
|
|
268
|
+
"registry": {
|
|
269
|
+
"loadBuiltins": true,
|
|
270
|
+
"customPath": ".elsabro/prompts"
|
|
271
|
+
},
|
|
272
|
+
"engine": {
|
|
273
|
+
"strictMode": false,
|
|
274
|
+
"escapeHtml": false
|
|
275
|
+
},
|
|
276
|
+
"experiments": {
|
|
277
|
+
"minSampleSize": 30,
|
|
278
|
+
"defaultMetrics": ["success_rate", "quality_score"]
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## Changelog
|
|
287
|
+
|
|
288
|
+
- **v3.3.0**: Initial Prompt Management System
|
|
289
|
+
- PromptRegistry with versioning
|
|
290
|
+
- TemplateEngine with Handlebars-like syntax
|
|
291
|
+
- PromptOptimizer for A/B testing
|
|
292
|
+
- Built-in templates
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# Sandbox Execution System (v3.2)
|
|
2
|
+
|
|
3
|
+
Sistema de ejecución aislada para código generado por agentes en entornos seguros y reproducibles.
|
|
4
|
+
|
|
5
|
+
## Arquitectura
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
9
|
+
│ SANDBOX EXECUTION LAYER │
|
|
10
|
+
├─────────────────────────────────────────────────────────────────────────┤
|
|
11
|
+
│ │
|
|
12
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
13
|
+
│ │ SANDBOX MANAGER │ │
|
|
14
|
+
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
|
|
15
|
+
│ │ │ Execution Request Queue │ │ │
|
|
16
|
+
│ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │
|
|
17
|
+
│ │ │ │ pending │→ │ running │→ │completed│ │ failed │ │ │ │
|
|
18
|
+
│ │ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │ │
|
|
19
|
+
│ │ └─────────────────────────────────────────────────────────┘ │ │
|
|
20
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
21
|
+
│ │ │
|
|
22
|
+
│ ▼ │
|
|
23
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
24
|
+
│ │ SANDBOX PROVIDERS │ │
|
|
25
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
26
|
+
│ │ │ Docker │ │ E2B │ │ Firecracker │ │ │
|
|
27
|
+
│ │ │ Container │ │ Sandbox │ │ microVM │ │ │
|
|
28
|
+
│ │ │ (default) │ │ (cloud) │ │ (fastest) │ │ │
|
|
29
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
30
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
31
|
+
│ │ │ Process │ │ WASM │ │ Remote │ │ │
|
|
32
|
+
│ │ │ (unsafe) │ │ (limited) │ │ (custom) │ │ │
|
|
33
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
34
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
35
|
+
│ │ │
|
|
36
|
+
│ ▼ │
|
|
37
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
38
|
+
│ │ RESOURCE CONTROLS │ │
|
|
39
|
+
│ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │ │
|
|
40
|
+
│ │ │ CPU │ │ Memory │ │ Disk │ │ Network │ │ │
|
|
41
|
+
│ │ │ limits │ │ limits │ │ limits │ │ policy │ │ │
|
|
42
|
+
│ │ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │ │
|
|
43
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
44
|
+
│ │
|
|
45
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## SandboxManager API
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
interface SandboxConfig {
|
|
54
|
+
provider: 'docker' | 'e2b' | 'firecracker' | 'process' | 'wasm' | 'remote';
|
|
55
|
+
image?: string;
|
|
56
|
+
environment?: Record<string, string>;
|
|
57
|
+
workdir?: string;
|
|
58
|
+
timeout?: number;
|
|
59
|
+
resources?: ResourceLimits;
|
|
60
|
+
network?: NetworkPolicy;
|
|
61
|
+
mounts?: Mount[];
|
|
62
|
+
capabilities?: string[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface ResourceLimits {
|
|
66
|
+
cpu?: { cores?: number; percent?: number };
|
|
67
|
+
memory?: { limitMb?: number; reservationMb?: number };
|
|
68
|
+
disk?: { limitMb?: number; readOnly?: boolean };
|
|
69
|
+
pids?: number;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
interface ExecutionResult {
|
|
73
|
+
id: string;
|
|
74
|
+
status: 'completed' | 'failed' | 'timeout' | 'killed';
|
|
75
|
+
exitCode: number;
|
|
76
|
+
stdout: string;
|
|
77
|
+
stderr: string;
|
|
78
|
+
duration_ms: number;
|
|
79
|
+
resources: ResourceUsage;
|
|
80
|
+
artifacts?: Artifact[];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
class SandboxManager {
|
|
84
|
+
// Run code in isolated sandbox
|
|
85
|
+
async run(code: string, language: string, config?: Partial<SandboxConfig>): Promise<ExecutionResult>;
|
|
86
|
+
|
|
87
|
+
// Run file in sandbox
|
|
88
|
+
async runFile(filePath: string, language: string, config?: Partial<SandboxConfig>): Promise<ExecutionResult>;
|
|
89
|
+
|
|
90
|
+
// Run with dependencies installed first
|
|
91
|
+
async runWithDeps(code: string, language: string, deps: string[], config?: Partial<SandboxConfig>): Promise<ExecutionResult>;
|
|
92
|
+
|
|
93
|
+
// Create interactive REPL session
|
|
94
|
+
async createSession(language: string, config?: Partial<SandboxConfig>): Promise<SandboxSession>;
|
|
95
|
+
|
|
96
|
+
// Kill running execution
|
|
97
|
+
async kill(executionId: string): Promise<void>;
|
|
98
|
+
|
|
99
|
+
// List active executions
|
|
100
|
+
listActive(): SandboxExecution[];
|
|
101
|
+
|
|
102
|
+
// Get provider status
|
|
103
|
+
async getProviderStatus(): Promise<ProviderStatus[]>;
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Providers
|
|
110
|
+
|
|
111
|
+
### DockerProvider (Default)
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
class DockerProvider implements SandboxProvider {
|
|
115
|
+
name = 'docker';
|
|
116
|
+
supportedLanguages = ['python', 'javascript', 'typescript', 'ruby', 'go', 'rust', 'java'];
|
|
117
|
+
|
|
118
|
+
async create(config: SandboxConfig): Promise<DockerSandbox> {
|
|
119
|
+
const container = await this.docker.createContainer({
|
|
120
|
+
Image: config.image || this.getDefaultImage(config.language),
|
|
121
|
+
HostConfig: {
|
|
122
|
+
Memory: (config.resources?.memory?.limitMb || 512) * 1024 * 1024,
|
|
123
|
+
NanoCpus: (config.resources?.cpu?.cores || 1) * 1e9,
|
|
124
|
+
PidsLimit: config.resources?.pids || 100,
|
|
125
|
+
NetworkMode: config.network?.enabled ? 'bridge' : 'none',
|
|
126
|
+
CapDrop: ['ALL'],
|
|
127
|
+
SecurityOpt: ['no-new-privileges']
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return new DockerSandbox(container, config);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
private getDefaultImage(language: string): string {
|
|
134
|
+
const images: Record<string, string> = {
|
|
135
|
+
'python': 'python:3.11-slim',
|
|
136
|
+
'javascript': 'node:20-slim',
|
|
137
|
+
'typescript': 'node:20-slim',
|
|
138
|
+
'ruby': 'ruby:3.2-slim',
|
|
139
|
+
'go': 'golang:1.21-alpine',
|
|
140
|
+
'rust': 'rust:1.75-slim',
|
|
141
|
+
'java': 'openjdk:21-slim'
|
|
142
|
+
};
|
|
143
|
+
return images[language] || 'ubuntu:22.04';
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### E2BProvider (Cloud)
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
class E2BProvider implements SandboxProvider {
|
|
152
|
+
name = 'e2b';
|
|
153
|
+
supportedLanguages = ['python', 'javascript', 'typescript'];
|
|
154
|
+
|
|
155
|
+
async create(config: SandboxConfig): Promise<E2BSandbox> {
|
|
156
|
+
const sandbox = await this.client.sandboxes.create({
|
|
157
|
+
template: this.getTemplate(config.language),
|
|
158
|
+
envVars: config.environment
|
|
159
|
+
});
|
|
160
|
+
return new E2BSandbox(sandbox, config);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### ProcessProvider (Local, Unsafe)
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
class ProcessProvider implements SandboxProvider {
|
|
169
|
+
name = 'process';
|
|
170
|
+
supportedLanguages = ['python', 'javascript', 'typescript', 'ruby', 'bash'];
|
|
171
|
+
|
|
172
|
+
async create(config: SandboxConfig): Promise<ProcessSandbox> {
|
|
173
|
+
// Warning: This provider runs code without isolation
|
|
174
|
+
console.warn('ProcessProvider: Running without sandboxing. Use only for trusted code.');
|
|
175
|
+
return new ProcessSandbox(config);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
## Interactive Sessions
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
class SandboxSession {
|
|
186
|
+
private sandbox: Sandbox;
|
|
187
|
+
private history: string[] = [];
|
|
188
|
+
|
|
189
|
+
// Execute single line/statement in REPL
|
|
190
|
+
async evaluate(input: string): Promise<string> {
|
|
191
|
+
this.history.push(input);
|
|
192
|
+
const result = await this.sandbox.run(input);
|
|
193
|
+
return result.stdout;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Get command history
|
|
197
|
+
getHistory(): string[] {
|
|
198
|
+
return [...this.history];
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Reset session state
|
|
202
|
+
async reset(): Promise<void> {
|
|
203
|
+
this.history = [];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Close session
|
|
207
|
+
async close(): Promise<void> {
|
|
208
|
+
await this.sandbox.cleanup();
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Integración con Agentes
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
class CodeRunnerAgent {
|
|
219
|
+
private sandboxManager: SandboxManager;
|
|
220
|
+
|
|
221
|
+
async runCode(task: AgentTask): Promise<AgentResult> {
|
|
222
|
+
const { code, language, dependencies } = task.input;
|
|
223
|
+
|
|
224
|
+
// Run in sandbox
|
|
225
|
+
const result = dependencies?.length
|
|
226
|
+
? await this.sandboxManager.runWithDeps(code, language, dependencies)
|
|
227
|
+
: await this.sandboxManager.run(code, language);
|
|
228
|
+
|
|
229
|
+
if (result.status === 'completed') {
|
|
230
|
+
return { success: true, output: result.stdout, artifacts: result.artifacts };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
success: false,
|
|
235
|
+
error: result.stderr,
|
|
236
|
+
suggestion: this.analyzeError(result.stderr, language)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Configuración
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"sandbox": {
|
|
249
|
+
"enabled": true,
|
|
250
|
+
"defaultProvider": "docker",
|
|
251
|
+
"defaultTimeout": 30000,
|
|
252
|
+
"defaultResources": {
|
|
253
|
+
"cpu": { "cores": 1 },
|
|
254
|
+
"memory": { "limitMb": 512 },
|
|
255
|
+
"disk": { "limitMb": 1024 },
|
|
256
|
+
"pids": 100
|
|
257
|
+
},
|
|
258
|
+
"defaultNetwork": { "enabled": false },
|
|
259
|
+
"providers": {
|
|
260
|
+
"docker": { "enabled": true, "socketPath": "/var/run/docker.sock" },
|
|
261
|
+
"e2b": { "enabled": false, "apiKey": null },
|
|
262
|
+
"process": { "enabled": true }
|
|
263
|
+
},
|
|
264
|
+
"languageDefaults": {
|
|
265
|
+
"python": { "image": "python:3.11-slim", "timeout": 60000 },
|
|
266
|
+
"javascript": { "image": "node:20-slim", "timeout": 30000 }
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## Seguridad
|
|
275
|
+
|
|
276
|
+
### Checklist de Seguridad
|
|
277
|
+
|
|
278
|
+
- [ ] **Network disabled by default**
|
|
279
|
+
- [ ] **Resource limits enforced** (CPU, memory, disk, PIDs)
|
|
280
|
+
- [ ] **Read-only filesystem** cuando sea posible
|
|
281
|
+
- [ ] **No capabilities** (dropped ALL by default)
|
|
282
|
+
- [ ] **No new privileges** (SecurityOpt enabled)
|
|
283
|
+
- [ ] **Timeout enforced** (kill after timeout)
|
|
284
|
+
- [ ] **Temp directories cleaned** (always cleanup)
|
|
285
|
+
- [ ] **No secrets exposed** (environment sanitized)
|
|
286
|
+
|
|
287
|
+
### Amenazas Mitigadas
|
|
288
|
+
|
|
289
|
+
| Amenaza | Mitigación |
|
|
290
|
+
|---------|------------|
|
|
291
|
+
| Fork bomb | PID limit |
|
|
292
|
+
| Memory exhaustion | Memory limit |
|
|
293
|
+
| Disk fill | Disk limit |
|
|
294
|
+
| Network exfiltration | Network disabled |
|
|
295
|
+
| Privilege escalation | No capabilities |
|
|
296
|
+
| Host file access | No mounts by default |
|
|
297
|
+
| Infinite loop | Timeout kill |
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## Changelog
|
|
302
|
+
|
|
303
|
+
- **v3.2.0**: Initial Sandbox Execution implementation
|