docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거

Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
This commit is contained in:
Antigravity Agent
2026-07-05 00:33:48 +09:00
parent 1cfd3bbb56
commit 9148c358d0
6455 changed files with 1 additions and 86875 deletions
@@ -0,0 +1,189 @@
---
id: ai-code-interpreter-sandbox
title: Code Interpreter — Sandbox / E2B / Daytona
category: Coding
status: draft
source_trust_level: B
verification_status: conceptual
created_at: 2026-05-09
updated_at: 2026-05-09
tags: [ai, code-execution, sandbox, e2b, vibe-coding]
tech_stack: { language: "TS / Python / Sandbox", applicable_to: ["Backend"] }
applied_in: []
aliases: [code interpreter, E2B, Daytona, sandbox, jupyter, python execution]
---
# Code Interpreter
> LLM 이 작성한 코드를 안전 실행. **격리된 sandbox** 가 핵심. E2B / Daytona / Modal / Cloudflare Containers / 자체 K8s. OpenAI Code Interpreter, Anthropic Bash tool 도 같은 패턴.
## 📖 핵심 개념
- Sandbox: 격리 + 자원 제한 + 시간 제한.
- Stateful: 한 세션 안 변수 유지 (Jupyter kernel).
- File I/O: upload + 결과 download.
- Streaming output.
## 💻 코드 패턴
### E2B Code Interpreter
```ts
import { Sandbox } from '@e2b/code-interpreter';
const sb = await Sandbox.create({ apiKey: process.env.E2B_API_KEY });
const exec = await sb.runCode(`
import pandas as pd
df = pd.read_csv('/data/sales.csv')
df.groupby('region').sum()
`);
console.log(exec.text); // stdout
console.log(exec.results); // 차트, table 등 rich result
console.log(exec.error);
await sb.kill();
```
### File upload / download
```ts
await sb.files.write('/data/sales.csv', csvBuffer);
const out = await sb.runCode(`
import matplotlib.pyplot as plt
df.plot()
plt.savefig('/out/chart.png')
`);
const png = await sb.files.read('/out/chart.png', 'binary');
```
### Streaming
```ts
const exec = await sb.runCode(longTask, {
onStdout: (line) => stream.write(line),
onStderr: (line) => stream.write(line),
});
```
### LLM tool 로 wrap
```ts
const tools = [{
name: 'execute_python',
description: 'Execute Python code in a sandbox. Files in /data/. Save outputs to /out/. State persists between calls in the same conversation.',
input_schema: {
type: 'object',
properties: { code: { type: 'string' } },
required: ['code'],
},
}];
async function executeTool(name: string, input: { code: string }) {
if (name === 'execute_python') {
const r = await sb.runCode(input.code);
return JSON.stringify({
stdout: r.text.slice(-2000),
error: r.error?.value,
results: r.results.map(x => ({ type: x.type, ...x })),
});
}
}
```
### 자원 제한
```ts
const sb = await Sandbox.create({
template: 'code-interpreter-v1',
timeoutMs: 60_000, // 세션 최대 1분
cpuCount: 1,
memoryMB: 512,
});
const exec = await sb.runCode(code, { timeoutMs: 30_000 }); // 1 cell 30초
```
### Persistent state (Jupyter)
```ts
await sb.runCode('x = 42');
const r = await sb.runCode('print(x * 2)'); // 84
```
### 자체 sandbox (Docker)
```dockerfile
FROM python:3.12-slim
RUN useradd -m sandbox
USER sandbox
WORKDIR /home/sandbox
RUN pip install pandas numpy matplotlib
```
```ts
import { spawn } from 'node:child_process';
async function runInDocker(code: string): Promise<string> {
return new Promise((resolve, reject) => {
const p = spawn('docker', [
'run', '--rm',
'--network', 'none',
'--memory', '512m',
'--cpus', '0.5',
'-i', 'python:3.12-slim',
'python', '-c', code,
]);
let out = ''; let err = '';
p.stdout.on('data', (d) => { out += d.toString(); });
p.stderr.on('data', (d) => { err += d.toString(); });
p.on('close', (c) => c === 0 ? resolve(out) : reject(new Error(err)));
setTimeout(() => p.kill(), 30_000);
});
}
```
⚠️ Docker 자체로 sandbox 부족 — gVisor / firecracker / E2B 권장.
### 출력 안전 처리
```ts
function sanitizeOutput(s: string): string {
return s
.replace(/[\x00-\x08\x0b-\x1f]/g, '') // control chars
.slice(0, 10_000); // 길이 제한
}
```
### 결과 caching (같은 코드)
```ts
const key = sha256(code + ':' + dataHash);
const cached = await cache.get(key);
if (cached) return cached;
const r = await sb.runCode(code);
await cache.set(key, r);
```
## 🤔 의사결정 기준
| 사용 | 추천 |
|---|---|
| ChatGPT-style data analysis | E2B Code Interpreter |
| Long-running compute | Modal / Daytona |
| Cloudflare 환경 | Cloudflare Containers |
| Self-hosted K8s | Pod per session + gVisor |
| 단순 calc | Python eval 위험 — math.js / sandbox js |
| Untrusted user code (CTF, 강의) | gVisor / Firecracker / E2B |
## ❌ 안티패턴
- **`eval()` 직접**: RCE. sandbox 필수.
- **Docker `--privileged`**: escape 가능.
- **Network 허용 + 무제한**: SSRF / 외부 호출.
- **Memory / CPU 무제한**: fork bomb / OOM.
- **Output 무제한 → LLM 으로**: 다음 turn 비싸짐.
- **Sandbox 재사용 cross-user**: state leak.
- **Filesystem 무제한 write**: 디스크 채움.
- **Timeout 없음**: 영원 hang.
## 🤖 LLM 활용 힌트
- E2B / Daytona 가 가장 modern.
- Sandbox = network none + memory limit + cpu limit + timeout.
- Output truncate 후 LLM 으로.
## 🔗 관련 문서
- [[AI_Function_Calling_Deep]]
- [[AI_Agentic_Patterns]]
- [[Security_OWASP_Top_10_Practical]]