{"slug":"access-your-tailnet-from-codesandbox","title":"Access your tailnet from CodeSandbox","tags":["tailscale","access-control"],"agent_summary":"Last validated: Jan 5, 2026","trigger_phrases":[],"runnable":false,"markdown":"\r\n# Access your tailnet from CodeSandbox\r\n\r\nLast validated: Jan 5, 2026\r\n\r\n[CodeSandbox](https://codesandbox.io/) is an online code editor and IDE for rapid web development.\r\n\r\nTailscale can be installed within a CodeSandbox Repository environment to be able to access private resources securely.\r\nYou can develop your application as if it were hosted in the same network as your other services, without\r\ncompromising security.\r\n\r\nTailscale works in CodeSandbox Repository environments by adding a container to a Dockerized application setup (for\r\nexample, using `docker-compose`). The additional container runs the Tailscale client and provides networking for the other\r\ncontainers.\r\n\r\n## [Integration](https://tailscale.com/docs/integrations/codesandbox\\#integration)\r\n\r\nFollow the [CodeSandbox instructions for getting Tailscale working in a CodeSandbox Repository](https://codesandbox.io/docs/learn/integrations/tailscale).\r\n\r\nYou'll need to:\r\n\r\n1. Create an [auth key](https://tailscale.com/docs/features/access-control/auth-keys) in the [Keys](https://login.tailscale.com/admin/settings/keys) page of the Tailscale admin console. The [key type](https://tailscale.com/docs/features/access-control/auth-keys#types-of-auth-keys)\r\nshould be reusable, ephemeral, and pre-authorized. You may also want to make the key type tagged, so your CodeSandbox\r\nenvironments are automatically labeled and granted access that is controlled by using [Tailscale access control policies](https://tailscale.com/docs/features/access-control).\r\n\r\n2. Add the auth key as a [CodeSandbox environment variable](https://codesandbox.io/docs/learn/environment/secrets), named `TS_AUTHKEY`.\r\n\r\n3. Add the [`tailscale/tailscale` Docker image](https://hub.docker.com/r/tailscale/tailscale) as an additional service beside your application.\r\n\r\n\r\n## [Authorization](https://tailscale.com/docs/integrations/codesandbox\\#authorization)\r\n\r\nAuthenticate to Tailscale from your workspace by referencing the `TS_AUTHKEY` environment variable in your Docker tasks\r\nwhen you start Tailscale. For example:\r\n\r\n```json\r\ndocker-compose exec tailscale tailscale up \\\r\n  --auth-key=${TS_AUTHKEY} --accept-routes --hostname=csb-${HOSTNAME}\r\n```\r\n\r\nYou can use the [visual policy editor](https://tailscale.com/docs/features/visual-editor) to manage your tailnet policy file. Refer to the [visual editor reference](https://tailscale.com/docs/reference/visual-editor) for guidance on using the visual editor.\r\n","html":"<h1>Access your tailnet from CodeSandbox</h1>\n<p>Last validated: Jan 5, 2026</p>\n<p><a href=\"https://codesandbox.io/\">CodeSandbox</a> is an online code editor and IDE for rapid web development.</p>\n<p>Tailscale can be installed within a CodeSandbox Repository environment to be able to access private resources securely.\r\nYou can develop your application as if it were hosted in the same network as your other services, without\r\ncompromising security.</p>\n<p>Tailscale works in CodeSandbox Repository environments by adding a container to a Dockerized application setup (for\r\nexample, using <code>docker-compose</code>). The additional container runs the Tailscale client and provides networking for the other\r\ncontainers.</p>\n<h2><a href=\"https://tailscale.com/docs/integrations/codesandbox#integration\">Integration</a></h2>\n<p>Follow the <a href=\"https://codesandbox.io/docs/learn/integrations/tailscale\">CodeSandbox instructions for getting Tailscale working in a CodeSandbox Repository</a>.</p>\n<p>You'll need to:</p>\n<ol>\n<li>\n<p>Create an <a href=\"https://tailscale.com/docs/features/access-control/auth-keys\">auth key</a> in the <a href=\"https://login.tailscale.com/admin/settings/keys\">Keys</a> page of the Tailscale admin console. The <a href=\"https://tailscale.com/docs/features/access-control/auth-keys#types-of-auth-keys\">key type</a>\r\nshould be reusable, ephemeral, and pre-authorized. You may also want to make the key type tagged, so your CodeSandbox\r\nenvironments are automatically labeled and granted access that is controlled by using <a href=\"https://tailscale.com/docs/features/access-control\">Tailscale access control policies</a>.</p>\n</li>\n<li>\n<p>Add the auth key as a <a href=\"https://codesandbox.io/docs/learn/environment/secrets\">CodeSandbox environment variable</a>, named <code>TS_AUTHKEY</code>.</p>\n</li>\n<li>\n<p>Add the <a href=\"https://hub.docker.com/r/tailscale/tailscale\"><code>tailscale/tailscale</code> Docker image</a> as an additional service beside your application.</p>\n</li>\n</ol>\n<h2><a href=\"https://tailscale.com/docs/integrations/codesandbox#authorization\">Authorization</a></h2>\n<p>Authenticate to Tailscale from your workspace by referencing the <code>TS_AUTHKEY</code> environment variable in your Docker tasks\r\nwhen you start Tailscale. For example:</p>\n<pre><code class=\"language-json\">docker-compose exec tailscale tailscale up \\\r\n  --auth-key=${TS_AUTHKEY} --accept-routes --hostname=csb-${HOSTNAME}\n</code></pre>\n<p>You can use the <a href=\"https://tailscale.com/docs/features/visual-editor\">visual policy editor</a> to manage your tailnet policy file. Refer to the <a href=\"https://tailscale.com/docs/reference/visual-editor\">visual editor reference</a> for guidance on using the visual editor.</p>\n"}