Skip to content

Commit b8a3140

Browse files
docs for git operations
1 parent ad5b944 commit b8a3140

4 files changed

Lines changed: 409 additions & 1 deletion

File tree

docs.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@
151151
"docs/commands/background"
152152
]
153153
},
154+
{
155+
"group": "Git",
156+
"pages": [
157+
"docs/git/authentication",
158+
"docs/git/clone",
159+
"docs/git/create-repo"
160+
]
161+
},
154162
{
155163
"group": "MCP Gateway",
156164
"pages": [
@@ -323,4 +331,4 @@
323331
"permanent": true
324332
}
325333
]
326-
}
334+
}

docs/git/authentication.mdx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
---
2+
title: "Git authentication"
3+
sidebarTitle: Authentication
4+
---
5+
6+
Use the `sandbox.git` helper to authenticate for private repositories. The helper does not perform interactive prompts, so pass credentials explicitly or store them.
7+
8+
<Note>
9+
Git is available in the default sandbox template. If you’re using a custom or minimal template without git, install it first. See the [install custom packages](/docs/quickstart/install-custom-packages) guide or add git in your [template definition](/docs/template/defining-template).
10+
</Note>
11+
12+
## Authenticate per command
13+
14+
For HTTP(S) repositories, pass `username` and `password` (token) to the command that needs it. A username is required whenever you pass a password/token.
15+
16+
<CodeGroup>
17+
```js JavaScript & TypeScript
18+
import { Sandbox } from '@e2b/code-interpreter'
19+
20+
const sandbox = await Sandbox.create()
21+
22+
await sandbox.git.push('/workspace/repo', {
23+
remote: 'origin',
24+
branch: 'main',
25+
setUpstream: true,
26+
username: process.env.GIT_USERNAME,
27+
password: process.env.GIT_TOKEN,
28+
})
29+
30+
await sandbox.git.pull('/workspace/repo', {
31+
remote: 'origin',
32+
branch: 'main',
33+
username: process.env.GIT_USERNAME,
34+
password: process.env.GIT_TOKEN,
35+
})
36+
```
37+
```python Python
38+
import os
39+
from e2b_code_interpreter import Sandbox
40+
41+
sandbox = Sandbox.create()
42+
43+
sandbox.git.push(
44+
'/workspace/repo',
45+
remote='origin',
46+
branch='main',
47+
set_upstream=True,
48+
username=os.environ.get('GIT_USERNAME'),
49+
password=os.environ.get('GIT_TOKEN'),
50+
)
51+
52+
sandbox.git.pull(
53+
'/workspace/repo',
54+
remote='origin',
55+
branch='main',
56+
username=os.environ.get('GIT_USERNAME'),
57+
password=os.environ.get('GIT_TOKEN'),
58+
)
59+
```
60+
</CodeGroup>
61+
62+
## Authenticate once (credential helper)
63+
64+
If you want to avoid passing credentials on each command, you can store them in the git credential helper inside the sandbox.
65+
66+
<Warning>
67+
`dangerouslyAuthenticate()` / `dangerously_authenticate()` stores credentials on disk inside the sandbox. Any process or agent with access to the sandbox can read them. Use only when you understand the risk.
68+
</Warning>
69+
70+
<CodeGroup>
71+
```js JavaScript & TypeScript
72+
import { Sandbox } from '@e2b/code-interpreter'
73+
74+
const sandbox = await Sandbox.create()
75+
76+
await sandbox.git.dangerouslyAuthenticate({
77+
username: process.env.GIT_USERNAME,
78+
password: process.env.GIT_TOKEN,
79+
host: 'github.com',
80+
protocol: 'https',
81+
})
82+
83+
// After this, HTTPS git operations can use the stored credentials.
84+
await sandbox.git.clone('https://github.com/org/private-repo.git', {
85+
path: '/workspace/repo',
86+
})
87+
await sandbox.git.push('/workspace/repo', { remote: 'origin', branch: 'main' })
88+
```
89+
```python Python
90+
import os
91+
from e2b_code_interpreter import Sandbox
92+
93+
sandbox = Sandbox.create()
94+
95+
sandbox.git.dangerously_authenticate(
96+
username=os.environ.get('GIT_USERNAME'),
97+
password=os.environ.get('GIT_TOKEN'),
98+
host='github.com',
99+
protocol='https',
100+
)
101+
102+
# After this, HTTPS git operations can use the stored credentials.
103+
sandbox.git.clone('https://github.com/org/private-repo.git', path='/workspace/repo')
104+
sandbox.git.push('/workspace/repo', remote='origin', branch='main')
105+
```
106+
</CodeGroup>
107+
108+
## Configure identity and config
109+
110+
Set the global git author and other config values as needed.
111+
112+
<CodeGroup>
113+
```js JavaScript & TypeScript
114+
await sandbox.git.configureUser('E2B Bot', 'bot@example.com')
115+
await sandbox.git.configSet('pull.rebase', 'false')
116+
const rebase = await sandbox.git.configGet('pull.rebase')
117+
```
118+
```python Python
119+
sandbox.git.configure_user('E2B Bot', 'bot@example.com')
120+
sandbox.git.config_set('pull.rebase', 'false')
121+
rebase = sandbox.git.config_get('pull.rebase')
122+
```
123+
</CodeGroup>

docs/git/clone.mdx

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
title: "Clone a repository"
3+
sidebarTitle: Clone
4+
---
5+
6+
Use the `sandbox.git` helper to clone repositories into the sandbox.
7+
8+
<Note>
9+
Git is available in the default sandbox template. If you’re using a custom or minimal template without git, install it first. See the [install custom packages](/docs/quickstart/install-custom-packages) guide or add git in your [template definition](/docs/template/defining-template).
10+
</Note>
11+
12+
## Basic clone
13+
14+
<CodeGroup>
15+
```js JavaScript & TypeScript
16+
import { Sandbox } from '@e2b/code-interpreter'
17+
18+
const sandbox = await Sandbox.create()
19+
20+
await sandbox.git.clone('https://github.com/org/repo.git', {
21+
path: '/workspace/repo',
22+
branch: 'main',
23+
depth: 1,
24+
})
25+
```
26+
```python Python
27+
from e2b_code_interpreter import Sandbox
28+
29+
sandbox = Sandbox.create()
30+
31+
sandbox.git.clone(
32+
'https://github.com/org/repo.git',
33+
path='/workspace/repo',
34+
branch='main',
35+
depth=1,
36+
)
37+
```
38+
</CodeGroup>
39+
40+
## Clone with credentials
41+
42+
For private repos over HTTP(S), pass `username` and `password` (token). By default, credentials are stripped from the remote URL after cloning.
43+
44+
<CodeGroup>
45+
```js JavaScript & TypeScript
46+
await sandbox.git.clone('https://github.com/org/private-repo.git', {
47+
path: '/workspace/private-repo',
48+
username: process.env.GIT_USERNAME,
49+
password: process.env.GIT_TOKEN,
50+
})
51+
```
52+
```python Python
53+
import os
54+
55+
sandbox.git.clone(
56+
'https://github.com/org/private-repo.git',
57+
path='/workspace/private-repo',
58+
username=os.environ.get('GIT_USERNAME'),
59+
password=os.environ.get('GIT_TOKEN'),
60+
)
61+
```
62+
</CodeGroup>
63+
64+
## Keep credentials in the remote URL
65+
66+
If you intentionally want to keep credentials in the cloned repository, set the `dangerouslyStoreCredentials` / `dangerously_store_credentials` flag.
67+
68+
<Warning>
69+
Storing credentials in the repository remote persists them in the repo config. Any process or agent with access to the sandbox can read them. Only use this when required.
70+
</Warning>
71+
72+
<CodeGroup>
73+
```js JavaScript & TypeScript
74+
await sandbox.git.clone('https://github.com/org/private-repo.git', {
75+
username: process.env.GIT_USERNAME,
76+
password: process.env.GIT_TOKEN,
77+
dangerouslyStoreCredentials: true,
78+
})
79+
```
80+
```python Python
81+
import os
82+
83+
sandbox.git.clone(
84+
'https://github.com/org/private-repo.git',
85+
username=os.environ.get('GIT_USERNAME'),
86+
password=os.environ.get('GIT_TOKEN'),
87+
dangerously_store_credentials=True,
88+
)
89+
```
90+
</CodeGroup>
91+
92+
## Status and branches
93+
94+
`status()` returns a structured object with branch, ahead/behind, and file status details. `branches()` returns the branch list and the current branch.
95+
96+
<CodeGroup>
97+
```js JavaScript & TypeScript
98+
const status = await sandbox.git.status('/workspace/repo')
99+
console.log(status.currentBranch, status.ahead, status.behind)
100+
console.log(status.fileStatus)
101+
102+
const branches = await sandbox.git.branches('/workspace/repo')
103+
console.log(branches.currentBranch)
104+
console.log(branches.branches)
105+
```
106+
```python Python
107+
status = sandbox.git.status('/workspace/repo')
108+
print(status.current_branch, status.ahead, status.behind)
109+
print(status.file_status)
110+
111+
branches = sandbox.git.branches('/workspace/repo')
112+
print(branches.current_branch)
113+
print(branches.branches)
114+
```
115+
</CodeGroup>
116+
117+
## Manage branches
118+
119+
<CodeGroup>
120+
```js JavaScript & TypeScript
121+
await sandbox.git.createBranch('/workspace/repo', 'feature/new-docs')
122+
await sandbox.git.checkoutBranch('/workspace/repo', 'main')
123+
await sandbox.git.deleteBranch('/workspace/repo', 'feature/old-docs', { force: true })
124+
```
125+
```python Python
126+
sandbox.git.create_branch('/workspace/repo', 'feature/new-docs')
127+
sandbox.git.checkout_branch('/workspace/repo', 'main')
128+
sandbox.git.delete_branch('/workspace/repo', 'feature/old-docs', force=True)
129+
```
130+
</CodeGroup>
131+
132+
## Stage and commit
133+
134+
<CodeGroup>
135+
```js JavaScript & TypeScript
136+
await sandbox.git.add('/workspace/repo', { all: true })
137+
await sandbox.git.commit('/workspace/repo', 'Initial commit', {
138+
authorName: 'E2B Bot',
139+
authorEmail: 'bot@example.com',
140+
})
141+
```
142+
```python Python
143+
sandbox.git.add('/workspace/repo', all=True)
144+
sandbox.git.commit(
145+
'/workspace/repo',
146+
'Initial commit',
147+
author_name='E2B Bot',
148+
author_email='bot@example.com',
149+
)
150+
```
151+
</CodeGroup>

0 commit comments

Comments
 (0)