Skip to content

Commit 6704961

Browse files
committed
Update README.md
1 parent f5fcd52 commit 6704961

File tree

1 file changed

+30
-23
lines changed

1 file changed

+30
-23
lines changed

README.md

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@ The Cloudflare Sandbox SDK enables you to run isolated code environments directl
3333

3434
## 🚀 Quick Start
3535

36-
### Prerequisites
37-
38-
- Node.js ≥ 18
39-
- Cloudflare account with [Containers platform access](https://blog.cloudflare.com/cloudflare-containers-coming-2025/)
40-
- Wrangler CLI installed (`npm install -g wrangler`)
41-
4236
### Installation
4337

4438
```bash
@@ -115,6 +109,7 @@ export default {
115109
### Core Methods
116110

117111
#### `exec(command, args, options?)`
112+
118113
Execute a command in the sandbox.
119114

120115
```typescript
@@ -123,13 +118,15 @@ console.log(result.stdout);
123118
```
124119

125120
#### `writeFile(path, content, options?)`
121+
126122
Write content to a file.
127123

128124
```typescript
129125
await sandbox.writeFile("/app.js", "console.log('Hello!');");
130126
```
131127

132128
#### `readFile(path, options?)`
129+
133130
Read a file from the sandbox.
134131

135132
```typescript
@@ -138,12 +135,13 @@ console.log(file.content);
138135
```
139136

140137
#### `gitCheckout(repoUrl, options?)`
138+
141139
Clone a git repository.
142140

143141
```typescript
144142
await sandbox.gitCheckout("https://github.com/user/repo", {
145143
branch: "main",
146-
targetDir: "my-project"
144+
targetDir: "my-project",
147145
});
148146
```
149147

@@ -177,7 +175,7 @@ export default {
177175

178176
// Your custom routes here
179177
// ...
180-
}
178+
},
181179
};
182180
```
183181

@@ -189,6 +187,7 @@ console.log(preview.url); // https://3000-sandbox-id.your-worker.dev
189187
```
190188

191189
The SDK handles:
190+
192191
- Production subdomain routing (`3000-sandbox-id.domain.com`)
193192
- Local development routing (`localhost:8787/preview/3000/sandbox-id`)
194193
- All localhost variants (127.0.0.1, ::1, etc.)
@@ -209,6 +208,7 @@ EXPOSE 3001 # For any additional services
209208
```
210209

211210
Without the `EXPOSE` instruction in local development, you'll see this error:
211+
212212
```
213213
connect(): Connection refused: container port not found. Make sure you exposed the port in your container definition.
214214
```
@@ -228,7 +228,9 @@ For more details, see the [Cloudflare Containers local development guide](https:
228228
const sandbox = getSandbox(env.Sandbox, "node-app");
229229

230230
// Write a simple Express server
231-
await sandbox.writeFile("/app.js", `
231+
await sandbox.writeFile(
232+
"/app.js",
233+
`
232234
const express = require('express');
233235
const app = express();
234236
@@ -237,7 +239,8 @@ await sandbox.writeFile("/app.js", `
237239
});
238240
239241
app.listen(3000);
240-
`);
242+
`
243+
);
241244

242245
// Install dependencies and start the server
243246
await sandbox.exec("npm", ["init", "-y"]);
@@ -263,11 +266,13 @@ const testResult = await sandbox.exec("npm", ["test"]);
263266
// Build the project
264267
const buildResult = await sandbox.exec("npm", ["run", "build"]);
265268

266-
return new Response(JSON.stringify({
267-
tests: testResult.exitCode === 0 ? "passed" : "failed",
268-
build: buildResult.exitCode === 0 ? "success" : "failed",
269-
output: testResult.stdout
270-
}));
269+
return new Response(
270+
JSON.stringify({
271+
tests: testResult.exitCode === 0 ? "passed" : "failed",
272+
build: buildResult.exitCode === 0 ? "success" : "failed",
273+
output: testResult.stdout,
274+
})
275+
);
271276
```
272277

273278
### Interactive Development Environment
@@ -294,14 +299,15 @@ await sandbox.writeFile("/src/App.jsx", updatedCode);
294299

295300
```typescript
296301
// Create and start a web server
297-
await sandbox.writeFile("/server.js", `
298-
Bun.serve({
302+
await sandbox.writeFile(
303+
"/server.js",
304+
`Bun.serve({
299305
port: 8080,
300306
fetch(req) {
301307
return new Response("Hello from sandbox!");
302308
}
303-
});
304-
`);
309+
});`
310+
);
305311

306312
await sandbox.exec("bun", ["run", "/server.js"]);
307313

@@ -359,14 +365,15 @@ Enable verbose logging:
359365

360366
```typescript
361367
const sandbox = getSandbox(env.Sandbox, "debug-sandbox");
362-
sandbox.client.onCommandStart = (cmd, args) => console.log(`Starting: ${cmd} ${args.join(' ')}`);
368+
sandbox.client.onCommandStart = (cmd, args) =>
369+
console.log(`Starting: ${cmd} ${args.join(" ")}`);
363370
sandbox.client.onOutput = (stream, data) => console.log(`[${stream}] ${data}`);
364-
sandbox.client.onCommandComplete = (success, code) => console.log(`Completed: ${success} (${code})`);
371+
sandbox.client.onCommandComplete = (success, code) =>
372+
console.log(`Completed: ${success} (${code})`);
365373
```
366374

367375
## 🚧 Known Limitations
368376

369-
- Containers require early access to Cloudflare's platform
370377
- Maximum container runtime is limited by Durable Object constraints
371378
- WebSocket support for preview URLs coming soon
372379
- Some system calls may be restricted in the container environment
@@ -407,4 +414,4 @@ Built with ❤️ by the Cloudflare team. Special thanks to all early adopters a
407414
<a href="https://discord.gg/cloudflaredev">Discord</a> •
408415
<a href="https://twitter.com/CloudflareDev">Twitter</a>
409416
</p>
410-
</div>
417+
</div>

0 commit comments

Comments
 (0)