Deno
Deno
deepagents와 함께 Deno 샌드박스 백엔드를 사용하면 Linux 마이크로VM에서 격리된 코드 실행이 가능해요.
Deno Deploy는 격리된 코드 실행을 위한 Linux 마이크로VM을 제공해요. Deno와 JavaScript 워크로드에 가장 적합합니다.
출처: 문서
본문
설정
npm install @langchain/deno
yarn add @langchain/deno
pnpm add @langchain/deno
인증
app.deno.com → 설정(Settings) → 조직 토큰(Organization Tokens)에서 토큰을 받으세요.
export DENO_DEPLOY_TOKEN=your_token
또는 자격 증명을 직접 전달하세요:
const sandbox = await DenoSandbox.create({
auth: { token: "your-token-here" },
});
deepagents와 함께 사용하기
import { createDeepAgent } from "deepagents";
import { ChatAnthropic } from "@langchain/anthropic";
import { DenoSandbox } from "@langchain/deno";
const sandbox = await DenoSandbox.create({
memoryMb: 1024,
lifetime: "10m",
});
try {
const agent = createDeepAgent({
model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
systemPrompt: "You are a coding assistant with sandbox access.",
backend: sandbox,
});
const result = await agent.invoke({
messages: [{ role: "user", content: "Create a hello world Deno app and run it" }],
});
} finally {
await sandbox.close();
}
단독 사용(Standalone usage)
import { DenoSandbox } from "@langchain/deno";
const sandbox = await DenoSandbox.create({
memoryMb: 1024,
lifetime: "10m",
});
const result = await sandbox.execute("deno --version");
console.log(result.output);
await sandbox.close();
구성(Configuration)
| 옵션(Option) | 타입(Type) | 기본값(Default) | 설명(Description) |
|---|---|---|---|
memoryMb |
number |
768 |
메모리(MB)(768-4096) |
lifetime |
"session" | string |
"session" |
수명("session", "5m", "30s") |
region |
string |
- | 리전. 옵션: "ams" | "ord" |
사용 가능한 리전(Available regions)
| 리전 코드(Region Code) | 위치(Location) |
|---|---|
ams |
암스테르담(Amsterdam) |
ord |
시카고(Chicago) |
수명 옵션(Lifetime options)
"session"(기본값): 클라이언트를 닫거나 dispose하면 샌드박스가 종료됨- 기간 문자열: 특정 시간 동안 샌드박스를 유지(예:
"5m","30s")
Deno SDK 접근하기
고급 기능을 위해 기본 Deno SDK에 접근하세요:
const denoSandbox = await DenoSandbox.create();
const sdk = denoSandbox.sandbox;
// Expose HTTP port
const url = await sdk.exposeHttp({ port: 3000 });
// Expose SSH
const ssh = await sdk.exposeSsh();
// Evaluate JavaScript
const result = await sdk.eval("1 + 2");
// Set environment variables
await sdk.env.set("API_KEY", "secret");
// Shell template literals
const output = await sdk.sh`echo "Hello from Deno!"`.text();
// Start a JavaScript runtime
const runtime = await sdk.createJsRuntime({ entrypoint: "server.ts" });
기존 샌드박스에 재연결하기
재연결은 기간 기반 수명(「"session"」이 아닌)이 필요합니다:
// Create with duration lifetime
const sandbox = await DenoSandbox.create({
memoryMb: 1024,
lifetime: "30m",
});
const sandboxId = sandbox.id;
await sandbox.close(); // Close connection, sandbox keeps running
// Later: reconnect
const reconnected = await DenoSandbox.connect(sandboxId);
const result = await reconnected.execute("ls -la");
팩토리 함수(Factory functions)
import { createDenoSandboxFactory, createDenoSandboxFactoryFromSandbox } from "@langchain/deno";
// Create new sandbox per invocation
const factory = createDenoSandboxFactory({ memoryMb: 1024 });
// Or reuse an existing sandbox across invocations
const sandbox = await DenoSandbox.create();
const reuseFactory = createDenoSandboxFactoryFromSandbox(sandbox);
오류 처리(Error handling)
import { DenoSandboxError } from "@langchain/deno";
try {
await sandbox.execute("some command");
} catch (error) {
if (error instanceof DenoSandboxError) {
switch (error.code) {
case "NOT_INITIALIZED":
await sandbox.initialize();
break;
case "COMMAND_TIMEOUT":
console.error("Command took too long");
break;
case "AUTHENTICATION_FAILED":
console.error("Check your Deno Deploy token");
break;
}
}
}
오류 코드(Error codes)
| 코드(Code) | 설명(Description) |
|---|---|
NOT_INITIALIZED |
샌드박스가 초기화되지 않음 - initialize() 호출 |
ALREADY_INITIALIZED |
두 번 초기화할 수 없음 |
AUTHENTICATION_FAILED |
유효하지 않거나 누락된 Deno Deploy 토큰 |
SANDBOX_CREATION_FAILED |
샌드박스 생성 실패 |
SANDBOX_NOT_FOUND |
샌드박스 ID를 찾을 수 없거나 만료됨 |
COMMAND_TIMEOUT |
명령 실행 타임아웃 |
COMMAND_FAILED |
명령 실행 실패 |
FILE_OPERATION_FAILED |
파일 읽기/쓰기 실패 |
RESOURCE_LIMIT_EXCEEDED |
CPU, 메모리, 스토리지 제한 초과 |
제한 사항(Limits and constraints)
| 제약(Constraint) | 값(Value) |
|---|---|
| 최소 메모리(Minimum memory) | 768 MB |
| 최대 메모리(Maximum memory) | 4096 MB (4 GB) |
| 디스크 공간(Disk space) | 10 GB |
| vCPU(vCPUs) | 2 |
| 작업 디렉터리(Working directory) | /home/app |
| 네트워크 접근(Network access) | 전체(기본값) |
환경 변수(Environment variables)
| 변수(Variable) | 설명(Description) |
|---|---|
DENO_DEPLOY_TOKEN |
Deno Deploy 조직 접근 토큰 |
더 알아보기 (Learn more)
- 이 문서를 MCP로 연결하면 Claude, VSCode 등에서 실시간 답변을 받을 수 있어요.
- GitHub에서 이 페이지 편집하기 또는 이슈 제출하기.