Checkpoint

This commit is contained in:
Onur Solmaz 2025-05-26 00:52:25 +02:00
parent c7e37a0830
commit b4b492cfae
7 changed files with 35 additions and 17 deletions

View file

@ -64,7 +64,7 @@ Create a `claude-sandbox.config.json` file:
```json
{
"dockerImage": "claude-sandbox:latest",
"dockerImage": "claude-code-sandbox:latest",
"dockerfile": "./custom.Dockerfile",
"detached": false,
"autoPush": true,
@ -147,7 +147,7 @@ The default Docker image includes:
Create a custom environment:
```dockerfile
FROM claude-sandbox:latest
FROM claude-code-sandbox:latest
# Add your tools
RUN apt-get update && apt-get install -y \

View file

@ -1,5 +1,5 @@
{
"dockerImage": "claude-sandbox:latest",
"dockerImage": "claude-code-sandbox:latest",
"dockerfile": null,
"detached": false,
"autoPush": true,

View file

@ -43,12 +43,12 @@ if [ ! -f /tmp/.branch-created ]; then\n\
else\n\
# After initial branch creation, prevent switching\n\
if [[ "$1" == "checkout" ]] && [[ "$2" != "-b" ]] && [[ "$*" != *"--"* ]]; then\n\
echo "Error: Branch switching is disabled in claude-sandbox"\n\
echo "Error: Branch switching is disabled in claude-code-sandbox"\n\
echo "You can only create new branches with git checkout -b"\n\
exit 1\n\
fi\n\
if [[ "$1" == "switch" ]]; then\n\
echo "Error: Branch switching is disabled in claude-sandbox"\n\
echo "Error: Branch switching is disabled in claude-code-sandbox"\n\
exit 1\n\
fi\n\
/usr/bin/git.real "$@"\n\

View file

@ -1,5 +1,5 @@
{
"name": "claude-sandbox",
"name": "claude-code-sandbox",
"version": "0.1.0",
"description": "Run Claude Code as an autonomous agent in Docker containers with git integration",
"main": "dist/index.js",

View file

@ -3,7 +3,7 @@ import path from 'path';
import { SandboxConfig } from './types';
const DEFAULT_CONFIG: SandboxConfig = {
dockerImage: 'claude-sandbox:latest',
dockerImage: 'claude-code-sandbox:latest',
detached: false,
autoPush: true,
autoCreatePR: true,

View file

@ -28,7 +28,7 @@ export class ContainerManager {
}
private async ensureImage(): Promise<void> {
const imageName = this.config.dockerImage || 'claude-sandbox:latest';
const imageName = this.config.dockerImage || 'claude-code-sandbox:latest';
// Check if image already exists
try {
@ -90,11 +90,11 @@ if [ ! -f /tmp/.branch-created ]; then\\n\\
else\\n\\
# After initial branch creation, prevent switching\\n\\
if [[ "$1" == "checkout" ]] && [[ "$2" != "-b" ]]; then\\n\\
echo "Branch switching is disabled in claude-sandbox"\\n\\
echo "Branch switching is disabled in claude-code-sandbox"\\n\\
exit 1\\n\\
fi\\n\\
if [[ "$1" == "switch" ]]; then\\n\\
echo "Branch switching is disabled in claude-sandbox"\\n\\
echo "Branch switching is disabled in claude-code-sandbox"\\n\\
exit 1\\n\\
fi\\n\\
/usr/bin/git "$@"\\n\\
@ -110,11 +110,21 @@ ENTRYPOINT ["/bin/bash", "-c"]
const pack = tarStream.pack();
// Add Dockerfile to tar
pack.entry({ name: 'Dockerfile' }, dockerfile);
pack.finalize();
pack.entry({ name: 'Dockerfile' }, dockerfile, (err: any) => {
if (err) throw err;
pack.finalize();
});
const buildStream = await this.docker.buildImage(pack, {
dockerfile: 'Dockerfile',
// Convert to buffer for docker
const chunks: Buffer[] = [];
pack.on('data', (chunk: any) => chunks.push(chunk));
await new Promise((resolve) => {
pack.on('end', resolve);
});
const tarBuffer = Buffer.concat(chunks);
const buildStream = await this.docker.buildImage(tarBuffer as any, {
t: imageName,
});
@ -123,6 +133,10 @@ ENTRYPOINT ["/bin/bash", "-c"]
this.docker.modem.followProgress(buildStream as any, (err: any, res: any) => {
if (err) reject(err);
else resolve(res);
}, (event: any) => {
if (event.stream) {
process.stdout.write(event.stream);
}
});
});
}
@ -142,6 +156,10 @@ ENTRYPOINT ["/bin/bash", "-c"]
this.docker.modem.followProgress(buildStream as any, (err: any, res: any) => {
if (err) reject(err);
else resolve(res);
}, (event: any) => {
if (event.stream) {
process.stdout.write(event.stream);
}
});
});
}
@ -157,8 +175,8 @@ ENTRYPOINT ["/bin/bash", "-c"]
// Create container
const container = await this.docker.createContainer({
Image: this.config.dockerImage || 'claude-sandbox:latest',
name: `${this.config.containerPrefix || 'claude-sandbox'}-${Date.now()}`,
Image: this.config.dockerImage || 'claude-code-sandbox:latest',
name: `${this.config.containerPrefix || 'claude-code-sandbox'}-${Date.now()}`,
Env: env,
HostConfig: {
Binds: volumes,

View file

@ -52,7 +52,7 @@ export class UIManager {
{ name: 'Continue working', value: 'nothing' },
{ name: 'Push branch to remote', value: 'push' },
{ name: 'Push branch and create PR', value: 'push-pr' },
{ name: 'Exit claude-sandbox', value: 'exit' },
{ name: 'Exit claude-code-sandbox', value: 'exit' },
],
},
]);