Skip to content

Conversation

christianalfoni
Copy link
Contributor

@christianalfoni christianalfoni commented Aug 25, 2025

Users are writing a lot of files to these Sandboxes to initialize them. This typically happens after forking the template. This batch operation ensures a faster and less "pressure" way of doing it. It should run both for Node and Browser.

A simple way to test is creating a test.ts file with something like:

import { CodeSandbox } from "@codesandbox/sdk";

const sdk = new CodeSandbox(process.env.CSB_API_TOKEN, {});
const sandbox = await sdk.sandboxes.create();
console.log("Connecting Sandbox...", sandbox.id);
const client = await sandbox.connect();
console.log("Writing files...");

const output = await client.fs.batchWrite([
  {
    path: "src/index.html",
    content: "hello world",
  },
  {
    path: "src/styles.css",
    content: "body { color: red }",
  },
]);

console.log("Created", sandbox.id, output);

Run it with npx vite-node test.ts

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Comment on lines +187 to +188
const result = await this.agentClient.shells.create(
this.agentClient.workspacePath,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just spitballing here, does this not potentially cause issues when the sandbox does something with zip files, e.g. watch them? I can't think of any use-cases realy, but I'm curious if we can handle this in another way. If not consider this comment resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking since it writes the zip file to a /temp directory that we should be good here 🤔

But we'll make this an RC and ask beta users who has write issues to test it out before releasing 😄

} finally {
// Always clean up the temporary zip file, regardless of success or failure
try {
await this.remove(tempZipPath);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@christianalfoni christianalfoni merged commit 493c5d5 into main Sep 2, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants