Skip to content

Commit a4ec46c

Browse files
authored
Add documentation for Template.aliasExists method (#81)
* Template aliases page * Simplify page, show just simple alias exists code example
1 parent 68323f2 commit a4ec46c

2 files changed

Lines changed: 178 additions & 0 deletions

File tree

docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
"docs/template/defining-template",
105105
"docs/template/start-ready-command",
106106
"docs/template/build",
107+
"docs/template/aliases",
107108
"docs/template/logging",
108109
"docs/template/error-handling",
109110
{

docs/template/aliases.mdx

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
title: "Template Aliases"
3+
sidebarTitle: "Aliases"
4+
description: "Understanding and managing template aliases"
5+
---
6+
7+
Template aliases are unique identifiers used to reference and create sandboxes from your templates. They serve as human-readable names that make it easy to identify and use your templates across your applications.
8+
9+
## What is a Template Alias?
10+
11+
An alias is a string identifier that you assign to a template when building it. Once a template is built with an alias, you can use that alias to create sandboxes from the template.
12+
13+
<CodeGroup>
14+
15+
```typescript JavaScript & TypeScript
16+
// Build a template with an alias
17+
await Template.build(template, {
18+
alias: 'my-python-env',
19+
cpuCount: 2,
20+
memoryMB: 2048,
21+
})
22+
23+
// Create a sandbox using the alias
24+
const sandbox = await Sandbox.create('my-python-env')
25+
```
26+
27+
```python Python
28+
# Build a template with an alias
29+
Template.build(
30+
template,
31+
alias='my-python-env',
32+
cpu_count=2,
33+
memory_mb=2048,
34+
)
35+
36+
# Create a sandbox using the alias
37+
sandbox = Sandbox(template='my-python-env')
38+
```
39+
40+
</CodeGroup>
41+
42+
## Uniqueness Requirement
43+
44+
<Warning>
45+
Template aliases must be **globally unique across the entire E2B platform**, not just within your team or account. This means if another user has already claimed an alias, you cannot use it for your template.
46+
</Warning>
47+
48+
When choosing an alias, consider using:
49+
- Your company or project name as a prefix (e.g., `acme-api-server`)
50+
- Version numbers or environment indicators (e.g., `myapp-v2`, `myapp-staging`)
51+
- Descriptive names that indicate the template's purpose (e.g., `data-analysis-python`)
52+
53+
## Common Use Cases
54+
55+
### Development and Production Environments
56+
57+
Use different aliases for different environments:
58+
59+
<CodeGroup>
60+
61+
```typescript JavaScript & TypeScript
62+
// Development template
63+
await Template.build(template, {
64+
alias: 'myapp-dev',
65+
cpuCount: 1,
66+
memoryMB: 1024,
67+
})
68+
69+
// Production template
70+
await Template.build(template, {
71+
alias: 'myapp-prod',
72+
cpuCount: 4,
73+
memoryMB: 4096,
74+
})
75+
```
76+
77+
```python Python
78+
# Development template
79+
Template.build(
80+
template,
81+
alias='myapp-dev',
82+
cpu_count=1,
83+
memory_mb=1024,
84+
)
85+
86+
# Production template
87+
Template.build(
88+
template,
89+
alias='myapp-prod',
90+
cpu_count=4,
91+
memory_mb=4096,
92+
)
93+
```
94+
95+
</CodeGroup>
96+
97+
### Multiple Template Variants
98+
99+
Create different variants of the same template with different configurations:
100+
101+
<CodeGroup>
102+
103+
```typescript JavaScript & TypeScript
104+
// Small instance
105+
await Template.build(template, {
106+
alias: 'myapp-small',
107+
cpuCount: 1,
108+
memoryMB: 512,
109+
})
110+
111+
// Large instance
112+
await Template.build(template, {
113+
alias: 'myapp-large',
114+
cpuCount: 8,
115+
memoryMB: 16384,
116+
})
117+
```
118+
119+
```python Python
120+
# Small instance
121+
Template.build(
122+
template,
123+
alias='myapp-small',
124+
cpu_count=1,
125+
memory_mb=512,
126+
)
127+
128+
# Large instance
129+
Template.build(
130+
template,
131+
alias='myapp-large',
132+
cpu_count=8,
133+
memory_mb=16384,
134+
)
135+
```
136+
137+
</CodeGroup>
138+
139+
<Tip>
140+
When building variants with the same template definition but different CPU/RAM configurations, E2B's caching system will reuse common layers, making subsequent builds much faster.
141+
</Tip>
142+
143+
## Checking Alias Availability
144+
145+
You can check if an alias is already in use with the `aliasExists` method.
146+
147+
<CodeGroup>
148+
149+
```typescript JavaScript & TypeScript
150+
import { Template } from 'e2b'
151+
152+
const exists = await Template.aliasExists('my-template')
153+
console.log(`Alias ${exists ? 'is taken' : 'is available'}`)
154+
```
155+
156+
```python Python
157+
from e2b import Template
158+
159+
exists = Template.alias_exists('my-template')
160+
print(f"Alias {'is taken' if exists else 'is available'}")
161+
```
162+
163+
```python Python (Async)
164+
from e2b import AsyncTemplate
165+
166+
exists = await AsyncTemplate.alias_exists('my-template')
167+
print(f"Alias {'is taken' if exists else 'is available'}")
168+
```
169+
170+
</CodeGroup>
171+
172+
## Best Practices
173+
174+
1. **Use descriptive names**: Choose aliases that clearly indicate the template's purpose or configuration
175+
2. **Include versioning**: Consider adding version numbers to your aliases for better version management (e.g., `myapp-v1`, `myapp-v2`)
176+
3. **Use consistent naming**: Establish a naming convention for your team and stick to it
177+
4. **Document your aliases**: Keep a record of which aliases are used for which purposes in your team

0 commit comments

Comments
 (0)