Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions examples/anthropic-claude-code-in-sandbox-js/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
E2B_API_KEY=your_e2b_api_key # Get one at https://e2b.dev/docs
ANTHROPIC_API_KEY=your_anthropic_api_key # Get one at https://console.anthropic.com/settings/keys
11 changes: 11 additions & 0 deletions examples/anthropic-claude-code-in-sandbox-js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
385 changes: 224 additions & 161 deletions examples/anthropic-claude-code-in-sandbox-js/package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions examples/anthropic-claude-code-in-sandbox-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"e2b:build:prod": "npx tsx src/build.prod.ts"
},
"dependencies": {
"dotenv": "^16.5.0",
"e2b": "^2.3.0"
"@e2b/code-interpreter": "^2.3.3",
"dotenv": "^17.2.3",
"e2b": "^2.8.2"
},
"devDependencies": {
"tsx": "^4.20.3"
"tsx": "^4.21.0"
}
}
9 changes: 6 additions & 3 deletions examples/anthropic-claude-code-in-sandbox-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import dotenv from "dotenv";
import fs from 'fs'
import "dotenv/config";
import { Sandbox } from "e2b";
import { templateName } from "./template";

dotenv.config();

const sbx = await Sandbox.create(templateName, {
envs: {
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
Expand All @@ -24,4 +23,8 @@ const result = await sbx.commands.run(

console.log(result.stdout);

const content = await sbx.files.read('/home/user/index.html')
// Write file to local filesystem
fs.writeFileSync('./index.html', content)

await sbx.kill();
15 changes: 15 additions & 0 deletions examples/anthropic-claude-code-in-sandbox-js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"moduleResolution": "bundler",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": false,
"resolveJsonModule": true,
"allowImportingTsExtensions": true,
"noEmit": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
2 changes: 2 additions & 0 deletions examples/anthropic-claude-code-in-sandbox-python/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
E2B_API_KEY=your_e2b_api_key # Get one at https://e2b.dev/docs
ANTHROPIC_API_KEY=your_anthropic_api_key # Get one at https://console.anthropic.com/settings/keys
28 changes: 10 additions & 18 deletions examples/anthropic-claude-code-in-sandbox-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,30 @@ Set the `E2B_API_KEY` in `.env`. You can get the API key at [https://e2b.dev/das
E2B_API_KEY="..."
```

**2. Change ANTHROPIC_API_KEY in the code**
**2. Set ANTHROPIC_API_KEY in `.env`**

Replace `<your api key>` in the code with your actual Anthropic API key.

**3. Initialize the virtual environment**
Add your Anthropic API key to the `.env` file:

```
python -m venv .venv
ANTHROPIC_API_KEY="..."
```

**4. Activate the virtual environment**

macOS/Unix
**3. Install Poetry** (if not already installed)

```
source .venv/bin/activate
curl -sSL https://install.python-poetry.org | python3 -
```

Windows

```
.venv\Scripts\activate
```
Or visit [https://python-poetry.org/docs/#installation](https://python-poetry.org/docs/#installation) for other installation methods.

**5. Install dependencies**
**4. Install dependencies**

```
pip install -e .
poetry install
```

**6. Run the example**
**5. Run the example**

```
python anthropic_claude_code_in_sandbox/main.py
poetry run start
```

This file was deleted.

40 changes: 40 additions & 0 deletions examples/anthropic-claude-code-in-sandbox-python/app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import os

from dotenv import load_dotenv
from e2b import Sandbox

from app.template import template_name


def main():
load_dotenv()

sbx = Sandbox.create(
template_name,
envs={
"ANTHROPIC_API_KEY": os.getenv("ANTHROPIC_API_KEY"),
},
)
print("Sandbox created", sbx.sandbox_id)

# Print help for Claude Code
# result = sbx.commands.run('claude --help')
# print(result.stdout)

# Run a prompt with Claude Code
result = sbx.commands.run(
"echo 'Create a hello world index.html' | claude -p --dangerously-skip-permissions",
timeout=0,
)
print(result.stdout)

content = sbx.files.read('/home/user/index.html')
# Write file to local filesystem
with open('./index.html', 'w') as file:
file.write(content)

sbx.kill()


if __name__ == "__main__":
main()
11 changes: 11 additions & 0 deletions examples/anthropic-claude-code-in-sandbox-python/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
</html>
Loading